-
Notifications
You must be signed in to change notification settings - Fork 23
/
jest-setup.ts
57 lines (51 loc) · 1.49 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
56
57
// Import Jest Native matchers
import '@testing-library/jest-native/extend-expect';
const mockedMedia = {
getTracks: jest.fn().mockReturnValue([
{
id: 'mocked-track-id',
kind: 'mocked-kind',
label: 'mocked-label',
enabled: true,
muted: false,
readyState: 'mocked-ready-state',
stop: jest.fn(),
},
]),
};
const mockedDevices = [
{
deviceId: 'mocked-device-id',
groupId: 'mocked-group-id',
kind: 'mocked-kind',
label: 'mocked-label',
},
];
jest.mock('react-native/Libraries/Utilities/Platform', () => ({
OS: 'ios',
select: jest.fn((selector) => selector.ios),
Version: '16.2',
constants: {
osVersion: '16.2',
systemName: 'iOS',
},
}));
// Mock the notifee module using the mock provided by @notifee/react-native itself
jest.mock('@notifee/react-native', () =>
require('@notifee/react-native/jest-mock')
);
jest.mock('react-native-reanimated', () => {
const RNReanimatedmock = require('react-native-reanimated/mock');
return { ...RNReanimatedmock, runOnUI: (fn: any) => fn };
});
// When mocking we implement only the needed navigator APIs, hence the suppression rule
global.navigator = {
// @ts-expect-error due to dom typing incompatible with RN
mediaDevices: {
getUserMedia: jest.fn().mockResolvedValue(mockedMedia),
enumerateDevices: jest.fn().mockResolvedValue(mockedDevices),
},
product: 'ReactNative',
};
// @ts-expect-error due to dom typing incompatible with RN
global.RTCPeerConnection = jest.fn();