-
Notifications
You must be signed in to change notification settings - Fork 16
/
jest_timers.javascript.txt
59 lines (40 loc) · 3.87 KB
/
jest_timers.javascript.txt
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
JEST_TIMERS
VERSION ==> #Package within Jest monorepo (see its doc)
#Based on @sinonjs/fake-timers
/=+===============================+=\
/ : : \
)==: CORE :==(
\ :_______________________________: /
\=+===============================+=/
JEST.useFakeTimers([TIMERS_CONF]) #Mocks clear|setTimeout|Interval|Immediate and process.nextTick()
JEST.useRealTimers() #Unmocks
CONF.fakeTimers #TIMERS_CONF
TIMERS_CONF.enableGlobally #BOOL (def: false). Calls JEST.useFakeTimers()
TIMERS_CONF.doNotFake #'FUNC'_ARR (def: [])
TIMERS_CONF.timerLimit #Like @sinonjs/fake-timers OPTS.loopLimit NUM (def: 1e5)
TIMERS_CONF.advanceTimers #Like @sinonjs/fake-timers OPTS.shouldAdvanceTime BOOL and OPTS.advanceTimeDelta NUM (def: false)
TIMERS_CONF.now #Like @sinonjs/fake-timers
TIMERS_CONF.legacyFakeTimers #BOOL (def: false)
JEST.clearAllTimers() #Clears all setTimeout|Interval|Immediate() and process.nextTick()
JEST.getTimerCount()->NUM #Number of fake timers
JEST.setSystemTime(DATE_NUM) #
JEST.getSystemTime()->DATE_NUM #
JEST.now()->DATE_NUM #
JEST-MOCK-NOW ==> ##Mocks Date.now() so it always return the same DATE
/=+===============================+=\
/ : : \
)==: ADVANCE :==(
\ :_______________________________: /
\=+===============================+=/
AUTOMATIC ADVANCE ==> #At end of any async test, automatically advances setImmediate() and process.nextTick() timers
#until there are no more left.
#This is done even if fake timers are disabled
JEST.advanceTimersByTime(NUM) #Advance timers mocks (except process.nextTick()) by NUMms
JEST.advanceTimersToNextTimer() #Advance timers mocks (except process.nextTick()) to next one
JEST.runAllTimers() #Advance timers mocks until there are no more left
JEST.runAllImmediates() #Like runAllTimers() for only setImmediate()
JEST.runAllTicks() #Like runAllTimers() for only process.nextTick()
JEST.runOnlyPendingTimers() #Like runAllTimers() but if new timers are registered by them, those timers are advanced but not run
JEST.*Async()->PROMISE #Same as above but async