Skip to content

Commit

Permalink
chore(ns): added test for issue oozcitak#178, removed console.log
Browse files Browse the repository at this point in the history
  • Loading branch information
svobik7 committed Apr 22, 2024
1 parent 4d1f29f commit 466c819
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 2 deletions.
2 changes: 0 additions & 2 deletions src/builder/XMLBuilderImpl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -384,8 +384,6 @@ export class XMLBuilderImpl implements XMLBuilder {
clone.prefix ? clone.prefix + ':' + clone.localName : clone.localName
);
const namespace = hostNode.lookupNamespaceURI(prefix)
console.log(prefix, namespace)

new XMLBuilderImpl(clone)._updateNamespace(namespace)
}
};
Expand Down
57 changes: 57 additions & 0 deletions test/issues/issue-178.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import $$ from '../TestHelpers';

describe('Replicate issue', () => {
// https://github.com/oozcitak/xmlbuilder2/issues/90
describe(`#178 - Namespace is removed when importing fragments.`, () => {
const expectedOutput = $$.t`<?xml version="1.0"?><Root xmlns="ns1"><Parent xmlns="ns2"><Child xmlns="ns3"><GrandChild xmlns="ns4">txt</GrandChild></Child></Parent></Root>`;
describe(`with defined namespaces on each element`, () => {
test(`using .ele()`, () => {
const doc = $$.create();
const root = doc.ele('ns1', 'Root');
const parent = root.ele('ns2', 'Parent');
const child = parent.ele('ns3', 'Child');
child.ele('ns4', 'GrandChild').txt('txt');

expect(doc.end()).toBe(expectedOutput);
});
test(`using .import()`, () => {
const doc = $$.create();
const root = doc.ele('ns1', 'Root');
const parent = $$.fragment().ele('ns2', 'Parent');
const child = $$.fragment().ele('ns3', 'Child');
const grandChild = $$.fragment().ele('ns4', 'GrandChild').txt('txt');

child.import(grandChild);
parent.import(child);
root.import(parent);

expect(doc.end()).toBe(expectedOutput);
});
});
describe(`with undefined namespaces on parent element`, () => {
const expectedOutput = $$.t`<?xml version="1.0"?><Root xmlns="ns1"><Parent><Child xmlns="ns3"><GrandChild xmlns="ns4">txt</GrandChild></Child></Parent></Root>`;
test(`using .ele()`, () => {
const doc = $$.create();
const root = doc.ele('ns1', 'Root');
const parent = root.ele('Parent');
const child = parent.ele('ns3', 'Child');
child.ele('ns4', 'GrandChild').txt('txt');

expect(doc.end()).toBe(expectedOutput);
});
test(`using .import()`, () => {
const doc = $$.create();
const root = doc.ele('ns1', 'Root');
const parent = $$.fragment().ele('Parent');
const child = $$.fragment().ele('ns3', 'Child');
const grandChild = $$.fragment().ele('ns4', 'GrandChild').txt('txt');

child.import(grandChild);
parent.import(child);
root.import(parent);

expect(doc.end()).toBe(expectedOutput);
});
});
});
});

0 comments on commit 466c819

Please sign in to comment.