From 864b920568df38f1c184c077162dc7d09c7004f3 Mon Sep 17 00:00:00 2001 From: ka-vaNu Date: Thu, 26 Dec 2024 13:21:20 +0100 Subject: [PATCH] #233 fixed tests and searchVal --- lib/tools.js | 4 ++-- lib/tools.test.js | 13 +++++++------ 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/lib/tools.js b/lib/tools.js index 6f06acc..6581496 100644 --- a/lib/tools.js +++ b/lib/tools.js @@ -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; } /** diff --git a/lib/tools.test.js b/lib/tools.test.js index d53434b..95c22db 100644 --- a/lib/tools.test.js +++ b/lib/tools.test.js @@ -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; }); });