Skip to content

Commit 466c819

Browse files
committed
chore(ns): added test for issue oozcitak#178, removed console.log
1 parent 4d1f29f commit 466c819

File tree

2 files changed

+57
-2
lines changed

2 files changed

+57
-2
lines changed

src/builder/XMLBuilderImpl.ts

-2
Original file line numberDiff line numberDiff line change
@@ -384,8 +384,6 @@ export class XMLBuilderImpl implements XMLBuilder {
384384
clone.prefix ? clone.prefix + ':' + clone.localName : clone.localName
385385
);
386386
const namespace = hostNode.lookupNamespaceURI(prefix)
387-
console.log(prefix, namespace)
388-
389387
new XMLBuilderImpl(clone)._updateNamespace(namespace)
390388
}
391389
};

test/issues/issue-178.test.ts

+57
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
import $$ from '../TestHelpers';
2+
3+
describe('Replicate issue', () => {
4+
// https://github.com/oozcitak/xmlbuilder2/issues/90
5+
describe(`#178 - Namespace is removed when importing fragments.`, () => {
6+
const expectedOutput = $$.t`<?xml version="1.0"?><Root xmlns="ns1"><Parent xmlns="ns2"><Child xmlns="ns3"><GrandChild xmlns="ns4">txt</GrandChild></Child></Parent></Root>`;
7+
describe(`with defined namespaces on each element`, () => {
8+
test(`using .ele()`, () => {
9+
const doc = $$.create();
10+
const root = doc.ele('ns1', 'Root');
11+
const parent = root.ele('ns2', 'Parent');
12+
const child = parent.ele('ns3', 'Child');
13+
child.ele('ns4', 'GrandChild').txt('txt');
14+
15+
expect(doc.end()).toBe(expectedOutput);
16+
});
17+
test(`using .import()`, () => {
18+
const doc = $$.create();
19+
const root = doc.ele('ns1', 'Root');
20+
const parent = $$.fragment().ele('ns2', 'Parent');
21+
const child = $$.fragment().ele('ns3', 'Child');
22+
const grandChild = $$.fragment().ele('ns4', 'GrandChild').txt('txt');
23+
24+
child.import(grandChild);
25+
parent.import(child);
26+
root.import(parent);
27+
28+
expect(doc.end()).toBe(expectedOutput);
29+
});
30+
});
31+
describe(`with undefined namespaces on parent element`, () => {
32+
const expectedOutput = $$.t`<?xml version="1.0"?><Root xmlns="ns1"><Parent><Child xmlns="ns3"><GrandChild xmlns="ns4">txt</GrandChild></Child></Parent></Root>`;
33+
test(`using .ele()`, () => {
34+
const doc = $$.create();
35+
const root = doc.ele('ns1', 'Root');
36+
const parent = root.ele('Parent');
37+
const child = parent.ele('ns3', 'Child');
38+
child.ele('ns4', 'GrandChild').txt('txt');
39+
40+
expect(doc.end()).toBe(expectedOutput);
41+
});
42+
test(`using .import()`, () => {
43+
const doc = $$.create();
44+
const root = doc.ele('ns1', 'Root');
45+
const parent = $$.fragment().ele('Parent');
46+
const child = $$.fragment().ele('ns3', 'Child');
47+
const grandChild = $$.fragment().ele('ns4', 'GrandChild').txt('txt');
48+
49+
child.import(grandChild);
50+
parent.import(child);
51+
root.import(parent);
52+
53+
expect(doc.end()).toBe(expectedOutput);
54+
});
55+
});
56+
});
57+
});

0 commit comments

Comments
 (0)