25 lines
769 B
TypeScript
25 lines
769 B
TypeScript
import { getCorrectDOM } from '../../src/utils/html.utils';
|
||
|
||
describe('html.utils - getCorrectDOM', () => {
|
||
it('retourne le document quand le composant n’existe pas', () => {
|
||
const dom = getCorrectDOM('component-inexistant');
|
||
expect(dom).toBe(document);
|
||
});
|
||
|
||
it('retourne le shadowRoot si présent, sinon document', () => {
|
||
const host = document.createElement('div');
|
||
host.setAttribute('id', 'host');
|
||
const shadow = host.attachShadow({ mode: 'open' });
|
||
document.body.appendChild(host);
|
||
|
||
const querySpy = jest.spyOn(document, 'querySelector');
|
||
querySpy.mockReturnValue(host as any);
|
||
|
||
const dom = getCorrectDOM('#host');
|
||
expect(dom).toBe(shadow);
|
||
|
||
querySpy.mockRestore();
|
||
document.body.removeChild(host);
|
||
});
|
||
});
|