-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathjest.setup.js
More file actions
50 lines (46 loc) · 1.6 KB
/
Copy pathjest.setup.js
File metadata and controls
50 lines (46 loc) · 1.6 KB
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
// Extend Jest "expect" functionality with Testing Library assertions.
import "@testing-library/jest-dom";
// Polyfill "window.fetch" used in the React component.
import "whatwg-fetch";
import { server } from "./src/__tests__/mocks/server";
import { LOCAL_STORAGE } from "./src/constants/localStorage";
// Replace react-player/lazy with react-player
// Fix Segmentation Fault when using 'react-player/lazy' in tests
// Learn more: https://github.com/cookpete/react-player/issues/1391
jest.mock("react-player/lazy", () => {
return jest.requireActual("react-player");
});
// Establish API mocking before all tests.
beforeAll(() => {
Storage.prototype.getItem = jest.fn().mockImplementation((key) => {
if (key === LOCAL_STORAGE.auth.active) {
return JSON.stringify({
uri: "http://localhost:3000",
token: "token",
});
}
});
return server.listen();
});
beforeEach(() => {
// IntersectionObserver isn't available in test environment
const mockIntersectionObserver = jest.fn();
mockIntersectionObserver.mockReturnValue({
observe: () => null,
unobserve: () => null,
disconnect: () => null,
});
window.IntersectionObserver = mockIntersectionObserver;
const mockResizeObserver = jest.fn();
mockResizeObserver.mockReturnValue({
observe: () => null,
unobserve: () => null,
disconnect: () => null,
});
global.ResizeObserver = mockResizeObserver;
});
// Reset any request handlers that we may add during the tests,
// so they don't affect other tests.
afterEach(() => server.resetHandlers());
// Clean up after the tests are finished.
afterAll(() => server.close());