Skip to content
This repository was archived by the owner on Jan 7, 2021. It is now read-only.

Commit 7bb5c1c

Browse files
author
Clément
committed
test(json2xml): write test for option ignoreNull
1 parent 2d87cdb commit 7bb5c1c

File tree

4 files changed

+34
-5
lines changed

4 files changed

+34
-5
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<subObject propertyNotNull="value"></subObject>
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<subObject propertyNotNull="value"><propertyNull></propertyNull></subObject>

test/fixtures/null-properties.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"subObject": {"propertyNotNull": "value","propertyNull":null}}

test/test.js

Lines changed: 31 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ describe('xml2json', function () {
220220
var xml = internals.readFixture('alternate-text-node-A.xml');
221221
var result = parser.toJson(xml, {reversible: true});
222222
var json = internals.readFixture('alternate-text-node-A.json');
223-
223+
224224
expect(result).to.equal(json);
225225

226226
done();
@@ -231,13 +231,13 @@ describe('xml2json', function () {
231231
var xml = internals.readFixture('alternate-text-node-A.xml');
232232
var result = parser.toJson(xml, {alternateTextNode: false, reversible: true});
233233
var json = internals.readFixture('alternate-text-node-A.json');
234-
234+
235235
expect(result).to.equal(json);
236236

237237
done();
238238
});
239239

240-
240+
241241
it('B: uses alternate text node with option as true', function(done) {
242242

243243
var xml = internals.readFixture('alternate-text-node-A.xml');
@@ -248,13 +248,13 @@ describe('xml2json', function () {
248248

249249
done();
250250
});
251-
251+
252252
it('C: overrides text node with option as "xx" string', function(done) {
253253

254254
var xml = internals.readFixture('alternate-text-node-A.xml');
255255
var result = parser.toJson(xml, {alternateTextNode: "xx", reversible: true});
256256
var json = internals.readFixture('alternate-text-node-C.json');
257-
257+
258258
expect(result).to.equal(json);
259259

260260
done();
@@ -299,6 +299,32 @@ describe('json2xml', function () {
299299

300300
done();
301301
});
302+
303+
describe('ignore null', function () {
304+
305+
it('ignore null properties {ignoreNull: true}', function (done) {
306+
307+
var json = JSON.parse( internals.readFixture('null-properties.json') );
308+
var expectedXml = internals.readFixture('null-properties-ignored.xml');
309+
310+
var xml = parser.toXml(json, {ignoreNull: true});
311+
expect(xml).to.equal(expectedXml);
312+
313+
done();
314+
});
315+
316+
it('don\'t ignore null properties (default)', function (done) {
317+
318+
var json = JSON.parse( internals.readFixture('null-properties.json') );
319+
var expectedXml = internals.readFixture('null-properties-not-ignored.xml');
320+
321+
var xml = parser.toXml(json);
322+
expect(xml).to.equal(expectedXml);
323+
324+
done();
325+
});
326+
327+
});
302328
});
303329

304330

0 commit comments

Comments
 (0)