import { render, CustomElement, Host, ShadowDOM, defineElement, state, prop } from "@cerxes/csx";
import { testContainer } from "../utils/test-container";
import { nextAnimationFrame } from "../utils/next-animation-frame";
describe("Shadow-DOM tests", () => {
/**
* Assert that shadow dom behaves as expected
*/
test("Simple shadow-component", async () => {
@defineElement('shadow-component')
class ShadowComponent extends CustomElement{
@prop()
title = 'Content here';
render(){
return (
{this.title}
)
}
}
let initialVSpec = ;
let rendered = render(initialVSpec);
let container = testContainer(rendered);
document.body.appendChild(container);// Components need to be added to the DOM or their connectecCallback will not be called
// Initial render
expect(
container.innerHTML
).toBe([
``,
``,
].join(''));
expect(
rendered.shadowRoot.innerHTML
).toBe([
`
`,
`
Content here
`,
``,
`
`,
].join(''));
// Update behaves as it should
let updatedVSpec = (
contents
);
render(updatedVSpec, {host: rendered, old: initialVSpec});
// Wait for it to update
await nextAnimationFrame();
expect(
container.innerHTML
).toBe([
``,
`
)
}
}
let initialVSpec = ;
let rendered = render(initialVSpec);
let container = testContainer(rendered);
document.body.appendChild(container);// Components need to be added to the DOM or their connectecCallback will not be called
// Initial render
expect(
container.innerHTML
).toBe([
``,
`
`,
``,
].join(''));
for(let i = 0; i < rendered.todos.length; ++i){
let todo = rendered.todos[i];
let el = rendered.rendered[i];
expect(el).not.toBeUndefined();
expect(
el.shadowRoot.innerHTML
).toBe([
``,
``
].join(''));
}
document.body.removeChild(container);
});
});