forked from chakra-ui/chakra-ui
-
Notifications
You must be signed in to change notification settings - Fork 0
/
vitest.setup.ts
42 lines (36 loc) · 1.15 KB
/
vitest.setup.ts
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
34
35
36
37
38
39
40
41
42
import "@testing-library/jest-dom/vitest"
import { expect } from "vitest"
import "vitest-axe/extend-expect"
import * as matchers from "vitest-axe/matchers"
expect.extend(matchers)
const { getComputedStyle } = window
window.getComputedStyle = (elt) => getComputedStyle(elt)
window.Element.prototype.scrollTo = () => {}
window.scrollTo = () => {}
if (typeof window.matchMedia !== "function") {
Object.defineProperty(window, "matchMedia", {
enumerable: true,
configurable: true,
writable: true,
value: vi.fn().mockImplementation((query) => ({
matches: false,
media: query,
onchange: null,
addListener: vi.fn(), // Deprecated
removeListener: vi.fn(), // Deprecated
addEventListener: vi.fn(),
removeEventListener: vi.fn(),
dispatchEvent: vi.fn(),
})),
})
}
// Workaround https://github.com/jsdom/jsdom/issues/2524#issuecomment-897707183
global.TextEncoder = require("util").TextEncoder
global.ResizeObserver = vi.fn().mockImplementation(() => ({
observe: vi.fn(),
unobserve: vi.fn(),
disconnect: vi.fn(),
}))
window.HTMLCanvasElement.prototype.getContext = vi
.fn()
.mockImplementation(() => ({}))