-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbun-test-setup.ts
More file actions
33 lines (30 loc) · 1 KB
/
bun-test-setup.ts
File metadata and controls
33 lines (30 loc) · 1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import "@testing-library/jest-dom"
import { JSDOM } from "jsdom"
// Create a new JSDOM instance
const dom = new JSDOM("<!DOCTYPE html><html><body></body></html>", {
url: "http://localhost",
pretendToBeVisual: true,
})
// Set up global variables for the test environment
global.window = dom.window as unknown as Window & typeof globalThis
global.document = dom.window.document
global.navigator = dom.window.navigator
global.HTMLElement = dom.window.HTMLElement
global.Element = dom.window.Element
// Suppress jsdom navigation warnings
const originalConsoleError = console.error
console.error = (...args: any[]) => {
const message = args[0]?.toString?.() || args[0]
if (message?.includes?.("navigation to another Document")) {
return
}
originalConsoleError(...args)
}
const originalConsoleWarn = console.warn
console.warn = (...args: any[]) => {
const message = args[0]?.toString?.() || args[0]
if (message?.includes?.("navigation to another Document")) {
return
}
originalConsoleWarn(...args)
}