Skip to content

Commit

Permalink
Merge pull request #239 from ka-vaNu/233-tempsensorac-elapsedtimes-bl…
Browse files Browse the repository at this point in the history
…eibt-auf-1-uptime-wird-nicht-aktualisiert

#233 fixed tests and searchVal
  • Loading branch information
ka-vaNu authored Dec 26, 2024
2 parents 15e71a7 + 864b920 commit 9ba035b
Showing 2 changed files with 9 additions and 8 deletions.
4 changes: 2 additions & 2 deletions lib/tools.js
Original file line number Diff line number Diff line change
@@ -49,12 +49,12 @@ function isArray(it) {
* @returns The value of the found property, or undefined if not found.
*/
function findVal(obj, prop) {
prop = `${prop}`.toLowerCase();
for (let p in obj) {
if (Object.prototype.hasOwnProperty.call(obj, p) && prop == `${p}`.toLowerCase()) {
if (prop.toLowerCase() == p.toLowerCase()) {
return obj[p];
}
}
return null;
}

/**
13 changes: 7 additions & 6 deletions lib/tools.test.js
Original file line number Diff line number Diff line change
@@ -93,27 +93,28 @@ describe('Test tools.isArray', function () {

describe('Test tools.findVal', function () {
it('search lower same case', function () {
expect(tools.findVal(objCaseInsensitive, 'testlower')).to.equal('lower');
expect(tools.findVal(objCaseInsensitive, 'testlower')).to.equal(objCaseInsensitive.testlower);
});

it('search lower different case', function () {
expect(tools.findVal(objCaseInsensitive, 'TESTLOWER')).to.equal('lower');
expect(tools.findVal(objCaseInsensitive, 'TESTLOWER')).to.equal(objCaseInsensitive.testlower);
});

it('search UPPER same case', function () {
expect(tools.findVal(objCaseInsensitive, 'TESTUPPER')).to.equal('upper');
console.log(`objCaseInsensitive: ${objCaseInsensitive.TESTUPPER}`);
expect(tools.findVal(objCaseInsensitive, 'TESTUPPER')).to.equal(objCaseInsensitive.TESTUPPER);
});

it('search UPPER different case', function () {
expect(tools.findVal(objCaseInsensitive, 'testupper')).to.equal('upper');
expect(tools.findVal(objCaseInsensitive, 'testupper')).to.equal(objCaseInsensitive.TESTUPPER);
});

it('search Mixed', function () {
expect(tools.findVal(objCaseInsensitive, 'testmixed')).to.equal('mixed');
expect(tools.findVal(objCaseInsensitive, 'testmixed')).to.equal(objCaseInsensitive.TestMixed);
});

it('search not found', function () {
expect(tools.findVal(objCaseInsensitive, 'test')).to.be.undefined;
expect(tools.findVal(objCaseInsensitive, 'test')).to.be.null;
});
});

0 comments on commit 9ba035b

Please sign in to comment.