From 79442d18e532c34b560dcee1564a4b29384f6d7d Mon Sep 17 00:00:00 2001 From: Lance Stout Date: Fri, 29 Jan 2016 13:28:03 -0800 Subject: [PATCH] Include non-undefined data that is false-y instead of omitting. See #10 --- lib/stanza.js | 2 +- test/test.js | 37 ++++++++++++++++++++++++------------- 2 files changed, 25 insertions(+), 14 deletions(-) diff --git a/lib/stanza.js b/lib/stanza.js index 06436b4..c78100d 100644 --- a/lib/stanza.js +++ b/lib/stanza.js @@ -101,7 +101,7 @@ module.exports = function (JXT, opts) { } result[prop] = vals; } - } else if (val !== undefined && val !== false && val !== '') { + } else if (val !== undefined) { result[prop] = val; } } diff --git a/test/test.js b/test/test.js index 92cd2ff..1b2ca6f 100644 --- a/test/test.js +++ b/test/test.js @@ -373,7 +373,7 @@ test('multiExtending', function (t) { xml.multiSubs = [{text: 'one'}, {text: 'two'}]; var res = xml.toJSON(); - t.deepEqual(res, { fixed: 'fixedVal', multiSubs: [ { text: 'one' }, { text: 'two' } ], numberSub: 42 }); + t.same(res.multiSubs, [ { text: 'one' }, { text: 'two' }]); t.end(); }); @@ -387,24 +387,35 @@ test('json', function (t) { var res = xml.toJSON(); - t.deepEqual(res, { - 'fixed': 'fixedVal', - 'subJXT': {'text': 'bar'}, - 'attribute': 'foo', - 'numberSub': 42, - 'multiSubs': [{'text': 'bar'}] + t.same(res, { + attribute: 'foo', + boolAttribute: false, + boolSub: false, + fixed: 'fixedVal', + lang: '', + multiSubs: [ { text: 'bar' } ], + numberSub: 42, + subAttribute: '', + subJXT: { text: 'bar' }, + subText: '' }); var xml2 = new JXT(res); var res2 = xml2.toJSON(); - t.deepEqual(res2, { - 'fixed': 'fixedVal', - 'subJXT': {'text': 'bar'}, - 'attribute': 'foo', - 'numberSub': 42, - 'multiSubs': [{'text': 'bar'}] + t.same(res2, { + attribute: 'foo', + boolAttribute: false, + boolSub: false, + fixed: 'fixedVal', + lang: '', + multiSubs: [ { text: 'bar' } ], + numberSub: 42, + subAttribute: '', + subJXT: { text: 'bar' }, + subText: '' }); + t.end(); });