From 8ac5b7cb32f2854b20a99c9cea3a1c061af41051 Mon Sep 17 00:00:00 2001 From: Yousuf Almarzooqi Date: Tue, 3 Oct 2017 16:25:20 +0400 Subject: [PATCH] Committed by npm script. --- lib/js2xml.js | 8 ++------ package.json | 2 +- test/js2xml_test.js | 19 ++++++++++++++++++- 3 files changed, 21 insertions(+), 8 deletions(-) diff --git a/lib/js2xml.js b/lib/js2xml.js index aa33f21..44546a4 100644 --- a/lib/js2xml.js +++ b/lib/js2xml.js @@ -198,14 +198,10 @@ function hasContentCompact(element, options, anyContent) { } function writeElementCompact(element, name, options, depth, indent) { - var xml = ''; if (typeof element === 'undefined' || element === null) { - if (options.fullTagEmptyElement) { - return '<' + name + '>'; - } else { - return ''; - } + return options.fullTagEmptyElement ? '<' + name + '>' : '<' + name + '/>'; } + var xml = ''; if (name) { xml += '<' + name; if (typeof element !== 'object') { diff --git a/package.json b/package.json index 0eba87a..49e732c 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "xml-js", - "version": "1.5.0", + "version": "1.5.1", "description": "A convertor between XML text and Javascript object / JSON text.", "repository": { "type": "git", diff --git a/test/js2xml_test.js b/test/js2xml_test.js index 067dad0..6a67d67 100644 --- a/test/js2xml_test.js +++ b/test/js2xml_test.js @@ -694,7 +694,7 @@ describe('Testing js2xml.js:', function () { }); - fdescribe('case by kolis ', function () { + describe('case by kolis ', function () { // see https://github.com/nashwaan/xml-js/issues/31 var js = { parent: { @@ -729,6 +729,23 @@ describe('Testing js2xml.js:', function () { }); + describe('case by techborn ', function () { + // see https://github.com/nashwaan/xml-js/pull/32 + // var js = { + // example: { + // _text: 'value' + // } + // }; + var js = { + example: 'value' + }; + var xml = 'value'; + it('should convert element text without _text property', function () { + expect(convert.js2xml(js, {compact: true})).toEqual(xml); + }); + + }); + }); });