-
Notifications
You must be signed in to change notification settings - Fork 19
/
testing-setup.js
32 lines (28 loc) · 955 Bytes
/
testing-setup.js
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
import { expect, afterEach, describe, it } from 'vitest'
import { cleanup } from '@testing-library/react'
import matchers from '@testing-library/jest-dom/matchers'
import '@testing-library/jest-dom'
import '@testing-library/jest-dom/extend-expect'
// extends Vitest's expect method with methods from react-testing-library
expect.extend(matchers)
// Needed for globals
window.URL.createObjectURL = function () {}
// needed to get past watchMedia error.
// https://github.com/vitest-dev/vitest/issues/821
Object.defineProperty(window, 'matchMedia', {
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()
}))
})
// runs a cleanup after each test case (e.g. clearing jsdom)
afterEach(() => {
cleanup()
})