-
Notifications
You must be signed in to change notification settings - Fork 7
/
jest.setup.ts
34 lines (30 loc) · 1.06 KB
/
jest.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
import { beforeEach } from '@jest/globals';
import { toMatchImageSnapshot } from 'jest-image-snapshot';
expect.extend({ toMatchImageSnapshot });
beforeEach(() => {
const originalConsoleError = console.error;
jest.spyOn(console, 'error').mockImplementation((error, ...args) => {
// When testing the pages' Head component, we get the following error:
// "<html> cannot appear as a child of <div>."
// Because `@testing-library/react` renders the page in a div. We can
// safely ignore this error, since Gatsby will render the Head component
// in the <head> tag.
if (
typeof error === 'string' &&
error.includes('cannot appear as a child of') &&
args[0] === '<html>' &&
args[1] === 'div'
) {
return;
}
// Require tests to be wrapped in act(...).
if (
typeof error === 'string' &&
error.includes('was not wrapped in act(...).')
) {
originalConsoleError(error, ...args);
throw new Error('Test was not wrapped in act(...).');
}
originalConsoleError(error, ...args);
});
});