forked from evergrace-co/react-native-audio-pro
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjest.setup.js
More file actions
87 lines (80 loc) · 1.94 KB
/
jest.setup.js
File metadata and controls
87 lines (80 loc) · 1.94 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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
jest.useFakeTimers();
jest.mock('react-native', () => ({
Platform: {
OS: 'ios',
},
NativeModules: {
AudioPro: {
play: jest.fn(),
pause: jest.fn(),
resume: jest.fn(),
stop: jest.fn(),
ambientPlay: jest.fn(),
ambientStop: jest.fn(),
ambientPause: jest.fn(),
ambientResume: jest.fn(),
seekTo: jest.fn(),
seekForward: jest.fn(),
seekBack: jest.fn(),
setPlaybackSpeed: jest.fn(),
setVolume: jest.fn(),
clear: jest.fn(),
},
},
NativeEventEmitter: jest.fn().mockImplementation(() => ({
addListener: jest.fn(() => ({ remove: jest.fn() })),
removeListener: jest.fn(),
})),
}));
const mockState = {
playerState: 'PLAYING',
position: 0,
duration: 0,
trackPlaying: { url: 'https://example.com/audio.mp3' },
volume: 1.0,
playbackSpeed: 1.0,
configureOptions: {
progressIntervalMs: 1000,
},
error: null,
debug: false,
debugIncludesProgress: false,
};
const mockActions = {
setTrackPlaying: jest.fn(),
setError: jest.fn(),
setPlaybackSpeed: jest.fn(),
setVolume: jest.fn(),
setConfigureOptions: jest.fn(),
setDebug: jest.fn(),
setDebugIncludesProgress: jest.fn(),
updateFromEvent: jest.fn(),
};
function createInternalStoreMock(modulePath) {
jest.mock(modulePath, () => {
const internalStore = jest.fn((selector) => selector(mockState));
internalStore.getState = () => ({
...mockState,
...mockActions,
});
internalStore.setState = jest.fn();
internalStore.subscribe = jest.fn();
return { internalStore };
});
}
function createEmitterMock(modulePath) {
jest.mock(modulePath, () => ({
emitter: {
emit: jest.fn(),
addListener: jest.fn(() => ({ remove: jest.fn() })),
},
ambientEmitter: {
emit: jest.fn(),
addListener: jest.fn(() => ({ remove: jest.fn() })),
},
}));
}
createInternalStoreMock('./src/internalStore');
createInternalStoreMock('./.conductor/hong-kong/src/internalStore');
createEmitterMock('./src/emitter');
createEmitterMock('./.conductor/hong-kong/src/emitter');