const {DOMParser} = require('linkedom'); const document = (new DOMParser).parseFromString('', 'text/html'); globalThis.document = document; const {render, html, svg} = require('../cjs'); const {Event} = document.defaultView; const {body} = document; const fragment = () => html`

1

2

`; const variousContent = content => html`${content}`; render(body, html`this is a test`); render(body, html`this is a ${ [1, 2].map(n => html`${n}`) } test`); render(body, html`this is a ${ [1, 2].map(n => svg`${n}`) } test`); (function twice(i) { render(body, html`this is a ${ (i ? [1, 2, 3] : [1, 2]).map(n => svg`${n}`) } test`); if (i--) twice(i); }(1)); render(body, html`this is a ${'test'}`); render(body, html`this is a ${true}`); render(body, html`this is a ${1} ${2} ${3}`); render(body, html`this is a ${1}`); let div = document.createElement('div'); render(div, html.node`this is a test`); render(div, html.for(body)`this is a test`); render(div, html.for(body, 1)`this is a test`); render(div, () => html.for(body)`this is a test`); render(div, () => html.for(body, 1)`this is a test`); (function twice(i) { render(div, () => html.for(body)`this is a test`); render(div, () => html.for(body, 1)`this is a test`); if (i--) twice(i); }(1)); let clicked = false; render(div, html`
{ clicked = true; }} .disabled=${true} .contentEditable=${false} null=${null} />`); div.firstElementChild.dispatchEvent(new Event('click')); console.assert(clicked, '@click worked'); clicked = false; render(div, html`
{ clicked = true; }} .disabled=${true} .contentEditable=${false} null=${null} />`); div.firstElementChild.dispatchEvent(new Event('click')); console.assert(clicked, 'onclick worked'); render(document.createElement('div'), html``); render(document.createElement('div'), html``); const sameWire = content => html`
${content}
`; render(div, sameWire([fragment()])); render(div, sameWire([])); render(div, sameWire([fragment()])); render(div, html``); render(div, variousContent([ html`

`, html`

` ])); render(div, variousContent([ html`

`, html`

`, html`

` ])); render(div, variousContent([ html`

` ])); render(div, html``); render(div, variousContent('text')); render(div, variousContent(null)); render(div, variousContent(void 0)); render(div, variousContent([true])); render(div, variousContent([1])); render(div, variousContent(['one'])); const reference = {}; render(div, html`

test
`); console.assert(reference.hasOwnProperty('current')); const fnReference = node => { fnReference.node = node; }; render(div, html`
test
`); console.assert(fnReference.node === div.firstElementChild); const withHandler = handler => html`
`; render(div, withHandler(Object)); render(div, withHandler(Object)); render(div, withHandler(String)); render(div, withHandler(null)); render(div, withHandler([Object, false])); const withAttribute = value => html`
`; render(div, withAttribute(null)); render(div, withAttribute('test')); render(div, withAttribute('test')); render(div, withAttribute(null)); render(div, withAttribute('test')); const withText = value => html``; render(div, withText('test')); render(div, withText('test')); render(div, withText(null)); render(div, withText('test')); render(div, html`${document.createDocumentFragment()}`); const wire1 = html`

`; const wire2 = html`

`; const wire = what => html`${what}`; render(div, wire([wire1, fragment(), wire2])); render(div, wire([wire2, fragment(), wire1])); render(div, html``); render(div, html``); try { render(div, html`

`); console.assert(false, 'broken template is not breaking'); } catch (OK) {} render(div, sameWire('test')); render(div, sameWire('test')); render(div, sameWire(document.createElement('p'))); const sameAttribute = value => html`
`; render(body, sameAttribute(1)); render(body, sameAttribute(null)); render(body, sameAttribute(null)); render(body, sameAttribute(2)); render(body, sameAttribute(3)); render(body, html`

${'hole'}

`); render(body, html`

${{no: "op"}}

`); render(body, html`

test

`); render(body, html`

test

test

`); render(body, html`${fragment()}`); render(body, html`${fragment()}`); render(body, html`${[fragment()]}`); render(body, html`

${'content'}

`); render(body, html`
{}} .disabled=${true} .contentEditable=${false} null=${null} />`); render(body, variousContent([ html`

`, html`

` ])); render(body, variousContent([ html`

`, html`

`, html`

` ])); render(body, variousContent([ html`

` ])); render(body, html`

`); console.assert(body.firstElementChild.getAttribute('role') === 'button', 'aria=${role}'); console.assert(body.firstElementChild.getAttribute('aria-labelledBy') === 'id', 'aria=${labelledBy}'); render(body, html`
`); console.assert(body.firstElementChild.dataset.labelledBy === 'id', '.dataset=${...}'); render(body, html`
`); console.assert(body.firstElementChild.getAttribute('thing') === '', '?thing=${truthy}'); render(body, html`
`); console.assert(!body.firstElementChild.hasAttribute('thing'), '?thing=${falsy}'); // cover importNode delete require.cache[require.resolve('../cjs/handlers.js')]; delete require.cache[require.resolve('../cjs/node.js')]; delete require.cache[require.resolve('../cjs/rabbit.js')]; delete require.cache[require.resolve('../cjs')]; const importNode = document.importNode; document.importNode = function () { return importNode.apply(this, arguments); }; const uhtml = require('../cjs'); uhtml.render(body, uhtml.html`${456}`);