Skip to content

Commit

Permalink
#233 fixed tests and searchVal
Browse files Browse the repository at this point in the history
  • Loading branch information
ka-vaNu committed Dec 26, 2024
1 parent e926739 commit 864b920
Show file tree
Hide file tree
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
Expand Up @@ -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;
}

/**
Expand Down
13 changes: 7 additions & 6 deletions lib/tools.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
});
});

Expand Down

0 comments on commit 864b920

Please sign in to comment.