Files
videospeed/tests/helpers/jsdom-globals.js
T
2026-04-10 15:04:29 -04:00

31 lines
989 B
JavaScript
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.
/**
* Point Vitest/jsdom test globals at a new JSDOM window (no document.write).
* Call after creating `new JSDOM(html, options).window`.
*/
import { vi } from "vitest";
export function applyJSDOMWindow(win) {
globalThis.window = win;
globalThis.document = win.document;
globalThis.navigator = win.navigator;
globalThis.customElements = win.customElements;
globalThis.HTMLElement = win.HTMLElement;
globalThis.Element = win.Element;
globalThis.Node = win.Node;
globalThis.Text = win.Text;
globalThis.DocumentFragment = win.DocumentFragment;
globalThis.Event = win.Event;
globalThis.MouseEvent = win.MouseEvent;
globalThis.KeyboardEvent = win.KeyboardEvent;
globalThis.DOMParser = win.DOMParser;
globalThis.URL = win.URL;
globalThis.Blob = win.Blob;
globalThis.FileReader = win.FileReader;
// Vitest fake timers patch host `Date`; jsdoms window keeps its own otherwise.
win.Date = globalThis.Date;
win.open = vi.fn();
win.close = vi.fn();
}