From 9bd3f6c79d19f05f044c16478aadee480a61325f Mon Sep 17 00:00:00 2001 From: Karthikeyan Govindaraj Date: Thu, 5 Apr 2018 11:43:17 -0700 Subject: [PATCH] Adding the test for undefined check --- .idea/workspace.xml | 59 +++++++++++++++++++++++++++++++++------------ index.js | 7 +++--- test/index.js | 2 ++ 3 files changed, 49 insertions(+), 19 deletions(-) diff --git a/.idea/workspace.xml b/.idea/workspace.xml index 5287ed6..bdc547b 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -27,8 +27,8 @@ - - + + @@ -36,8 +36,8 @@ - - + + @@ -72,10 +72,10 @@ - + @@ -142,21 +142,22 @@ + - - + - + - + @@ -178,6 +179,27 @@ + + + + + + + + + + + + + + + + + + + + + @@ -270,17 +292,24 @@ + + + + + + + - - + + - - + + diff --git a/index.js b/index.js index 707e670..a1aeb43 100644 --- a/index.js +++ b/index.js @@ -11,10 +11,6 @@ function nestedEmptyCheck(obj) { return true; } - else if(obj === undefined) { - return true; - } - else if(typeof obj === "boolean"){ return false; } @@ -62,6 +58,9 @@ function nestedEmptyCheck(obj) { * @returns {boolean} */ function isEmptyObj(object) { + if(object === undefined) + return true; + var objToSend = JSON.parse(JSON.stringify(object)); var result = nestedEmptyCheck(objToSend); if(JSON.stringify(result).indexOf('false') > -1) diff --git a/test/index.js b/test/index.js index a43d252..862b786 100644 --- a/test/index.js +++ b/test/index.js @@ -17,6 +17,7 @@ var k ={ system: [ { a: [1,2], c: [5,6], }, 2]} var l = {source: {}, type: "", pool: {}, acquireConnectionTimeout: '', system: [ { a: [], c: [] }, ] } var m = {a:" "} var n = {a:true} +var o = {a: undefined}; test('isEmptyObj Testing', function(assert) { @@ -34,6 +35,7 @@ test('isEmptyObj Testing', function(assert) { assert.equal(isEmptyObj(l), true); assert.equal(isEmptyObj(m), true); assert.equal(isEmptyObj(n), false); + assert.equal(isEmptyObj(o), true); assert.end() })