dev-test: DOM node hierarchy in the browser env; expect().toContain

The browser env exposed the HTML*Element constructors but not the
classes above them, so a library checking `instanceof Element` (as
react-tooltip does on every hover) threw "Element is not defined".
Node, Element, Document, DocumentFragment, Text, ShadowRoot and
SVGElement now come from JSDOM.

expect().toContain and .not.toContain were stubs. A string contains a
substring; any other iterable contains the item itself, not a
deep-equal copy, as in jest.
This commit is contained in:
Satoshi Qazi Muhammed committed 2026-10-10 08:56:58 +04:00
1 parent 0cd4f12cfb
commit 4e3bf04010
4 files changed
+82 -1

No files matched your search

+12
View File
@@ -24,6 +24,18 @@ describe('browser', () => {
expect(typeof all.HTMLElement).toBe('function');
});
it('contains the DOM node hierarchy', () => {
const div = document.createElement('div');
expect(div).toBeInstanceOf(Element);
expect(div).toBeInstanceOf(Node);
expect(document.createTextNode('text')).toBeInstanceOf(Text);
expect(document.createDocumentFragment()).toBeInstanceOf(DocumentFragment);
expect(document.createElementNS('http://www.w3.org/2000/svg', 'svg')).toBeInstanceOf(SVGElement);
expect(div.attachShadow({ mode: 'open' })).toBeInstanceOf(ShadowRoot);
expect(document).toBeInstanceOf(Document);
});
it('dispatches the global CustomEvent and Event on window', () => {
expect(() => window.dispatchEvent(new CustomEvent('custom', { detail: 1 }))).not.toThrow();
expect(() => window.dispatchEvent(new Event('plain'))).not.toThrow();