-
Notifications
You must be signed in to change notification settings - Fork 0
/
jest.setup.ts
45 lines (37 loc) · 1.16 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
35
36
37
38
39
40
41
42
43
44
45
import React from 'react';
import next from 'next';
import server from './__mocks__/serverMock';
import '@testing-library/jest-dom/extend-expect';
/**
* Configuration file for Jest & React Testing Library Unit Test environment
*
* @author Carl Scrivener {@link https://github.com/rapscallion45 GitHub}
* @since 0.0.0
*/
/** instatiate NexJS before running tests - this loads next.config.js */
next({ dev: true });
/** polyfill "window.fetch" used in the React component. */
import 'whatwg-fetch';
/** extend Jest "expect" functionality with Testing Library assertions. */
import '@testing-library/jest-dom';
/** get rid of useLayoutEffect warning when running tests */
React.useLayoutEffect = React.useEffect;
/** setup mock of next router */
jest.mock('next/router', () => require('next-router-mock'));
/** start test msw server */
beforeAll(() => {
server.listen({
/** every API should be mocked, error if an API is unhandled */
onUnhandledRequest: 'error',
});
});
/**
* reset handlers after each test just in case we need to
* reconfigure a handler for a specific test
*/
afterEach(() => {
server.resetHandlers();
});
afterAll(() => {
server.close();
});