forked from react-native-netinfo/react-native-netinfo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
jest.setup.js
55 lines (48 loc) · 1.38 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
48
49
50
51
52
53
54
55
/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @format
*/
/* eslint-env jest */
import {NativeModules} from 'react-native';
import {
NetInfoStateType,
NetInfoCellularGeneration,
} from './src/internal/types';
// Mock the RNCNetInfo native module to allow us to unit test the JavaScript code
NativeModules.RNCNetInfo = {
getCurrentState: jest.fn(),
addListener: jest.fn(),
removeListeners: jest.fn(),
};
NativeModules.RNCNetInfo.getCurrentState.mockResolvedValue({
type: NetInfoStateType.cellular,
isConnected: true,
isInternetReachable: true,
details: {
isConnectionExpensive: true,
cellularGeneration: NetInfoCellularGeneration['3g'],
},
});
// Reset the mocks before each test
global.beforeEach(() => {
jest.resetAllMocks();
NativeModules.RNCNetInfo.getCurrentState.mockResolvedValue({
type: NetInfoStateType.cellular,
isConnected: true,
isInternetReachable: true,
details: {
isConnectionExpensive: true,
cellularGeneration: NetInfoCellularGeneration['3g'],
},
});
require('./src/internal/deprecatedState').setup();
require('./src/internal/state').setup();
});
global.afterEach(() => {
require('./src/internal/deprecatedState').tearDown();
require('./src/internal/state').tearDown();
});