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

+10 -1
View File
@@ -22,8 +22,12 @@ export function browser () {
const { window } = new JSDOM('', { url: 'http://localhost' });
return {
// Event constructors, see BROWSER_OVERRIDES
// The DOM node hierarchy, which libraries check with instanceof, and the
// event constructors (Node has its own of these, see BROWSER_OVERRIDES)
CustomEvent: window.CustomEvent,
Document: window.Document,
DocumentFragment: window.DocumentFragment,
Element: window.Element,
Event: window.Event,
// All HTML Elements that are defined on the JSDOM window object.
// (we copied as-is from the types definition). We cannot get this
@@ -99,6 +103,11 @@ export function browser () {
HTMLUListElement: window.HTMLUListElement,
HTMLUnknownElement: window.HTMLUnknownElement,
HTMLVideoElement: window.HTMLVideoElement,
// the rest of the node hierarchy
Node: window.Node,
SVGElement: window.SVGElement,
ShadowRoot: window.ShadowRoot,
Text: window.Text,
// normal service resumes, the base top-level names
crypto: window.crypto,
document: window.document,