-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathjest.setup.js
48 lines (40 loc) · 1.07 KB
/
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
39
40
41
42
43
44
45
46
47
/* global jest fetch */
import * as mockCamera from './__mocks__/Camera';
jest.mock('Linking', () =>
({
addEventListener: jest.fn(),
removeEventListener: jest.fn(),
openURL: jest.fn(),
canOpenURL: jest.fn(),
getInitialURL: jest.fn(),
}),
);
jest.mock('react-native-push-notification', () => ({
addEventListener: jest.fn(),
removeEventListener: jest.fn(),
requestPermissions: jest.fn(),
configure: jest.fn(),
}));
// Mocking the global.fetch included in React Native
global.fetch = jest.fn();
// Helper to mock a success response (only once)
fetch.mockResponseSuccess = (body) => {
fetch.mockImplementationOnce(
() => Promise.resolve({ json: () => Promise.resolve(JSON.parse(body)) }),
);
};
// Helper to mock a failure response (only once)
fetch.mockResponseFailure = (error) => {
fetch.mockImplementationOnce(
() => Promise.reject(error),
);
};
jest.mock('react-native-img-cache', () => ({
DocumentDir: () => {},
ImageCache: {
get: {
clear: () => {},
},
},
}));
jest.mock('react-native-camera', () => mockCamera);