-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathjest-setup.ts
More file actions
32 lines (28 loc) · 887 Bytes
/
jest-setup.ts
File metadata and controls
32 lines (28 loc) · 887 Bytes
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
// In your own jest-setup.js (or any other name)
import '@testing-library/jest-dom';
export {};
declare global {
namespace jest {
interface Matchers<R> {
toHaveStyleRule(attr: string, value: string): R;
}
}
}
let consoleErrorMock: { mockRestore: () => void };
// React throws deprecation warnings when used without createRoot.
// Supress those errors in test until testing-library supports that by default.
beforeEach(() => {
const originalConsoleError = console.error;
consoleErrorMock = jest
.spyOn(console, 'error')
.mockImplementation((message, ...optionalParams) => {
// Ignore ReactDOM.render/ReactDOM.hydrate deprecation warning
if (message.indexOf('Use createRoot instead.') !== -1) {
return;
}
originalConsoleError(message, ...optionalParams);
});
});
afterEach(() => {
consoleErrorMock.mockRestore();
});