-
Notifications
You must be signed in to change notification settings - Fork 0
/
jest-setup.ts
55 lines (44 loc) · 1.03 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
46
47
48
49
50
51
52
53
54
55
import { setLogger } from 'react-query';
import { toHaveNoViolations } from 'jest-axe';
import { noop as _noop } from 'lodash';
import '@testing-library/jest-dom';
import { server } from './src/api-mocks/server';
import { DEFAULT_COORDS } from './src/app/config';
expect.extend(toHaveNoViolations);
const geolocationMock = {
getCurrentPosition: jest.fn().mockImplementationOnce((success) =>
Promise.resolve(
success({
coords: DEFAULT_COORDS,
})
)
),
};
// @ts-ignore
global.navigator.geolocation = geolocationMock;
const localStorageMock = {
getItem: jest.fn(),
setItem: jest.fn(),
removeItem: jest.fn(),
clear: jest.fn(),
length: 0,
key: jest.fn(),
};
global.localStorage = localStorageMock;
setLogger({
// eslint-disable-next-line no-console
log: console.log,
// eslint-disable-next-line no-console
warn: console.warn,
error: _noop,
});
beforeAll(() => {
server.listen();
});
afterEach(() => {
server.resetHandlers();
});
afterAll(() => {
server.close();
jest.clearAllMocks();
});