ihm_client/tests/unit/html.utils.test.ts

25 lines
769 B
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import { getCorrectDOM } from '../../src/utils/html.utils';
describe('html.utils - getCorrectDOM', () => {
it('retourne le document quand le composant nexiste 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);
});
});