Skip to content

Commit

Permalink
Include non-undefined data that is false-y instead of omitting.
Browse files Browse the repository at this point in the history
See #10
  • Loading branch information
legastero committed Jan 29, 2016
1 parent e9438c9 commit 79442d1
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 14 deletions.
2 changes: 1 addition & 1 deletion lib/stanza.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Expand Down
37 changes: 24 additions & 13 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});

Expand All @@ -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();
});

Expand Down

0 comments on commit 79442d1

Please sign in to comment.