import { createBlock, mount } from "../../src/blockdom"; import { makeTestFixture } from "./helpers"; //------------------------------------------------------------------------------ // Setup and helpers //------------------------------------------------------------------------------ const XHTML_URI = "http://www.w3.org/1999/xhtml"; const SVG_URI = "http://www.w3.org/2000/svg"; let fixture: HTMLElement; beforeEach(() => { fixture = makeTestFixture(); }); afterEach(() => { fixture.remove(); }); //------------------------------------------------------------------------------ // Tests //------------------------------------------------------------------------------ describe("namespace", () => { test("default namespace is xhtml", () => { const block = createBlock(``); const tree = block(); mount(tree, fixture); expect(fixture.innerHTML).toBe(""); expect(fixture.firstElementChild!.namespaceURI).toBe(XHTML_URI); }); test("namespace can be changed with block-ns", () => { const block = createBlock(``); const tree = block(); mount(tree, fixture); expect(fixture.innerHTML).toBe(""); expect(fixture.firstElementChild!.namespaceURI).toBe(SVG_URI); }); test("namespace is kept for children", () => { const block = createBlock( `` ); const tree = block(); mount(tree, fixture); expect(fixture.innerHTML).toBe( "" ); const parent = fixture.firstElementChild!; const child1 = parent.firstElementChild!; const subchild = child1.firstElementChild!; const child2 = child1.nextElementSibling!; expect(parent.namespaceURI).toBe(SVG_URI); expect(child1.namespaceURI).toBe(SVG_URI); expect(child2.namespaceURI).toBe(SVG_URI); expect(subchild.namespaceURI).toBe(SVG_URI); }); test("various namespaces in same block", () => { const block = createBlock(``); const tree = block(); mount(tree, fixture); expect(fixture.innerHTML).toBe(""); const none = fixture.firstElementChild!; const one = none.firstElementChild!; const two = one.nextElementSibling!; expect(none.namespaceURI).toBe(XHTML_URI); expect(one.namespaceURI).toBe("one"); expect(two.namespaceURI).toBe("two"); }); });