-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathjest.setup.js
38 lines (34 loc) · 913 Bytes
/
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
import '@testing-library/jest-dom/extend-expect';
import '@testing-library/jest-dom';
import { QueryCache } from 'react-query';
// src/setupTests.js
import { server } from './test/mocks/server';
// jest.mock('zustand');
jest.mock('next/router', () => ({
useRouter() {
return {
route: '/',
pathname: '',
query: '',
asPath: '',
push: jest.fn(),
events: {
on: jest.fn(),
off: jest.fn(),
},
beforePopState: jest.fn(() => null),
prefetch: jest.fn(() => null),
};
},
}));
// Establish API mocking before all tests.
beforeAll(() => server.listen());
// Reset any request handlers that we may add during the tests,
// so they don't affect other tests.
afterEach(() => {
const queryCache = new QueryCache();
server.resetHandlers();
queryCache.clear();
});
// Clean up after the tests are finished.
afterAll(() => server.close());