Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
it('upgrades elements inserted via importNode to detached element', async () => {
const name = generateName();
const iframe = await fixture('');
const foreignDocument = iframe.contentWindow.document;
foreignDocument.body.innerHTML = `<div><a is=""></a></div>`;
// eslint-disable-next-line prefer-destructuring
const nodeToImport = foreignDocument.body.children[0];
class Foo extends HTMLAnchorElement {}
defineCBE(Foo, 'a', name);
const wrapper = document.importNode(nodeToImport, true);
expect(wrapper.children[0] instanceof Foo).toBeTruthy();
});
});
it('calls the callback when the element is attached to the body', async () => {
class Foo extends HTMLAnchorElement {
connectedCallback() {
connectedCallbackSpy();
}
}
defineCBE(Foo, 'a');
const foo = new Foo();
const wrapper = await fixture('<div></div>');
const promise = waitForMutationObserverChange(
document.body,
observeChildren,
);
wrapper.appendChild(foo);
await promise;
expect(connectedCallbackSpy).toHaveBeenCalledTimes(1);
});
});
it('calls the callback for elements already existing on declaration', async () => {
const name = generateName();
await fixture(
`<div><a is=""></a></div>` +
`<div><div><div><a is=""></a></div></div></div>`,
);
class Foo extends HTMLAnchorElement {
connectedCallback() {
connectedCallbackSpy();
}
}
defineCBE(Foo, 'a', name);
expect(connectedCallbackSpy).toHaveBeenCalledTimes(2);
});