|
968 | 968 | res.should.equal("<base><a><![CDATA[b'c]]></a></base>"); |
969 | 969 | }); |
970 | 970 | }); |
| 971 | + |
| 972 | + describe("nodeAliasString", function () { |
| 973 | + |
| 974 | + it("should raise an error when options is defined and options.nodeAliasString is undefined", function () { |
| 975 | + var res; |
| 976 | + try { |
| 977 | + res = js2xmlparser(defaultRoot, defaultData, { |
| 978 | + nodeAliasString: undefined |
| 979 | + }); |
| 980 | + } catch (e) { |
| 981 | + e.should.match(/nodeAliasString option must be a string/); |
| 982 | + } |
| 983 | + should.not.exist(res); |
| 984 | + }); |
| 985 | + |
| 986 | + it("should raise an error when options is defined and options.nodeAliasString is an object", function () { |
| 987 | + var res; |
| 988 | + try { |
| 989 | + res = js2xmlparser(defaultRoot, defaultData, { |
| 990 | + nodeAliasString: {} |
| 991 | + }); |
| 992 | + } catch (e) { |
| 993 | + e.should.match(/nodeAliasString option must be a string/); |
| 994 | + } |
| 995 | + should.not.exist(res); |
| 996 | + }); |
| 997 | + |
| 998 | + it("should raise an error when options is defined and options.nodeAliasString is an array", function () { |
| 999 | + var res; |
| 1000 | + try { |
| 1001 | + res = js2xmlparser(defaultRoot, defaultData, { |
| 1002 | + nodeAliasString: [] |
| 1003 | + }); |
| 1004 | + } catch (e) { |
| 1005 | + e.should.match(/nodeAliasString option must be a string/); |
| 1006 | + } |
| 1007 | + should.not.exist(res); |
| 1008 | + }); |
| 1009 | + |
| 1010 | + it("should raise an error when options is defined and options.nodeAliasString is a number", function () { |
| 1011 | + var res; |
| 1012 | + try { |
| 1013 | + res = js2xmlparser(defaultRoot, defaultData, { |
| 1014 | + nodeAliasString: 2 |
| 1015 | + }); |
| 1016 | + } catch (e) { |
| 1017 | + e.should.match(/nodeAliasString option must be a string/); |
| 1018 | + } |
| 1019 | + should.not.exist(res); |
| 1020 | + }); |
| 1021 | + |
| 1022 | + it("should raise an error when options is defined and options.nodeAliasString is a boolean", function () { |
| 1023 | + var res; |
| 1024 | + try { |
| 1025 | + res = js2xmlparser(defaultRoot, defaultData, { |
| 1026 | + nodeAliasString: true |
| 1027 | + }); |
| 1028 | + } catch (e) { |
| 1029 | + e.should.match(/nodeAliasString option must be a string/); |
| 1030 | + } |
| 1031 | + should.not.exist(res); |
| 1032 | + }); |
| 1033 | + |
| 1034 | + it("should create XML with node alias string '=' when options.nodeAliasString is not specified", function () { |
| 1035 | + var res = js2xmlparser(defaultRoot, { |
| 1036 | + a: { |
| 1037 | + "=": "b" |
| 1038 | + } |
| 1039 | + }, defaultOptions); |
| 1040 | + res.should.equal("<base><b></b></base>"); |
| 1041 | + }); |
| 1042 | + |
| 1043 | + it("should create XML with node alias string '__alias' when options.nodeAliasString is '__alias'", function () { |
| 1044 | + var res = js2xmlparser(defaultRoot, { |
| 1045 | + a: { |
| 1046 | + "__alias": "b" |
| 1047 | + } |
| 1048 | + }, { |
| 1049 | + declaration: { |
| 1050 | + include: false |
| 1051 | + }, |
| 1052 | + prettyPrinting: { |
| 1053 | + enabled: false |
| 1054 | + }, |
| 1055 | + nodeAliasString: "__alias" |
| 1056 | + }); |
| 1057 | + res.should.equal("<base><b></b></base>"); |
| 1058 | + }); |
| 1059 | + |
| 1060 | + it("should create XML with options.nodeAliasString and data is an array", function () { |
| 1061 | + var res = js2xmlparser(defaultRoot, { |
| 1062 | + a: [{ |
| 1063 | + "=": "b" |
| 1064 | + }, { |
| 1065 | + "=": "c" |
| 1066 | + }] |
| 1067 | + }, defaultOptions); |
| 1068 | + res.should.equal("<base><b></b><c></c></base>"); |
| 1069 | + }); |
| 1070 | + |
| 1071 | + }) |
971 | 1072 | }); |
972 | 1073 |
|
973 | 1074 | describe("data", function () { |
|
0 commit comments