-
Notifications
You must be signed in to change notification settings - Fork 0
/
jest.setup.js
65 lines (57 loc) · 1.77 KB
/
jest.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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
/* eslint-disable @typescript-eslint/no-var-requires */
/* eslint-disable global-require */
const fetchMock = require('jest-fetch-mock')
const { toHaveNoViolations } = require('jest-axe')
const { createSerializer } = require('@emotion/jest')
expect.addSnapshotSerializer(createSerializer())
expect.extend(toHaveNoViolations)
fetchMock.enableMocks()
if (typeof window !== 'undefined') {
require('@testing-library/jest-dom')
Object.defineProperty(window, 'matchMedia', {
writable: true,
value: jest.fn().mockImplementation(query => ({
matches: false,
media: query,
onchange: null,
addListener: jest.fn(), // Deprecated
removeListener: jest.fn(), // Deprecated
addEventListener: jest.fn(),
removeEventListener: jest.fn(),
dispatchEvent: jest.fn(),
})),
})
}
// https://github.com/testing-library/react-testing-library/issues/459
// Supress act warning. TODO: Fix issue without supression
const originalError = console.error
const originalWarn = console.warn
beforeAll(() => {
// this is here to silence a warning temporarily
// we'll fix it in the next exercise
jest.spyOn(console, 'warn').mockImplementation((...args) => {
if (
typeof args[0] === 'string' &&
(args[0].includes('Warning: <Formik render>') ||
args[0].includes('Warning: componentWillMount'))
) {
return
}
originalWarn.call(console, ...args)
})
jest.spyOn(console, 'error').mockImplementation((...args) => {
if (
// eslint-disable-next-line operator-linebreak
typeof args[0] === 'string' &&
args[0].includes('Warning: An update to')
) {
return
}
originalError.call(console, ...args)
})
})
afterAll(() => {
if ('mockRestore' in console.error) {
console.error.mockRestore()
}
})