File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+
2+ import XMLBuilder from "../src/fxb.js" ;
3+ import { Expression } from "path-expression-matcher" ;
4+
5+ describe ( "Format without indentation" , function ( ) {
6+ const expectedXml = `
7+ <root>
8+ <child1>hello</child1>
9+ <child2>world</child2>
10+ </root>`
11+
12+ it ( "when order is preserved" , function ( ) {
13+ const jObj = [
14+ {
15+ root : [
16+ { child1 : [ { "#text" : "hello" } ] } ,
17+ { child2 : [ { "#text" : "world" } ] }
18+ ]
19+ }
20+ ] ;
21+
22+ const builderOptions = {
23+ format : true ,
24+ preserveOrder : true ,
25+ indentBy : ""
26+ } ;
27+
28+
29+ const builder = new XMLBuilder ( builderOptions ) ;
30+ let output = builder . build ( jObj ) ;
31+ // console.log(output);
32+ expect ( output ) . toEqual ( expectedXml ) ;
33+
34+ } ) ;
35+ xit ( "when order is not preserved" , function ( ) {
36+ // TODO: This test is failing due an extra line in the starting of the document
37+ // But not changing the behavior for backward compatibility.
38+ // Will be fixed in major release
39+ const jObj = {
40+ root : {
41+ child1 : "hello" ,
42+ child2 : "world" ,
43+ }
44+ }
45+
46+ const builderOptions = {
47+ format : true ,
48+ indentBy : ""
49+ } ;
50+
51+
52+ const builder = new XMLBuilder ( builderOptions ) ;
53+ let output = builder . build ( jObj ) ;
54+ //console.log(output);
55+ expect ( output ) . toEqual ( expectedXml ) ;
56+
57+ } ) ;
58+ } ) ;
Original file line number Diff line number Diff line change @@ -11,7 +11,7 @@ const EOL = "\n";
1111 */
1212export default function toXml ( jArray , options ) {
1313 let indentation = "" ;
14- if ( options . format && options . indentBy . length > 0 ) {
14+ if ( options . format ) {
1515 indentation = EOL ;
1616 }
1717
You can’t perform that action at this time.
0 commit comments