Total Complexity | 5 |
Complexity/F | 1.25 |
Lines of Code | 33 |
Function Count | 4 |
Duplicated Lines | 0 |
Ratio | 0 % |
Changes | 0 |
1 | const globalSetTimeout = global.setTimeout |
||
2 | |||
3 | exports.__esModule = true |
||
4 | |||
5 | exports.mockSetTimeout = expectedPause => { |
||
6 | const mockState = { |
||
7 | expectedPause: expectedPause, |
||
8 | passedTimeout: null, |
||
9 | numTimeoutCalls: 0, |
||
10 | // eslint-disable-next-line @typescript-eslint/no-empty-function |
||
11 | pendingCallback: () => {}, |
||
12 | pendingCallbackArgs: [], |
||
13 | } |
||
14 | |||
15 | global.setTimeout = (callback, ms, ...args) => { |
||
16 | if (ms !== mockState.expectedPause) { |
||
17 | // We use a "magic number" to allow all the other cases work as expected |
||
18 | return globalSetTimeout(callback, ms, ...args) |
||
19 | } |
||
20 | |||
21 | mockState.passedTimeout = ms |
||
22 | mockState.numTimeoutCalls += 1 |
||
23 | mockState.pendingCallback = callback |
||
24 | mockState.pendingCallbackArgs = args |
||
25 | return null |
||
26 | } |
||
27 | |||
28 | return mockState |
||
29 | } |
||
30 | |||
31 | exports.restoreSetTimeout = () => { |
||
32 | global.setTimeout = globalSetTimeout |
||
33 | } |
||
34 |