Files
pezkuwi-dev/packages/dev-test/src/env/browser.spec.ts
T
Satoshi Qazi Muhammed 0cd4f12cfb dev-test: JSDOM's Event and CustomEvent win over Node's in the browser env
Globals were only set where Node had none, and Node defines Event and
CustomEvent itself. Code running in the browser env therefore built
Node events, which a JSDOM node refuses: react-tooltip's
window.dispatchEvent(new CustomEvent(...)) threw "parameter 1 is not of
type 'Event'". In the browser env these two now come from JSDOM, as they
do under jest-environment-jsdom.
2026-10-10 08:53:49 +04:00

32 lines
914 B
TypeScript

// Copyright 2017-2026 @pezkuwi/dev-test authors & contributors
// SPDX-License-Identifier: Apache-2.0
import { browser } from './browser.js';
const all = browser();
describe('browser', () => {
it('contains window', () => {
expect(all.window).toBeDefined();
});
it('contains a crypto implementation', () => {
expect(all.crypto).toBeTruthy();
expect(typeof all.crypto.getRandomValues).toBe('function');
});
it('contains the top-level objects', () => {
expect(all.document).toBeDefined();
expect(all.navigator).toBeDefined();
});
it('contains HTML*Element', () => {
expect(typeof all.HTMLElement).toBe('function');
});
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();
});
});