-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathnode_tests_mocks.node.txt
45 lines (38 loc) · 2.27 KB
/
node_tests_mocks.node.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
┏━━━━━━━━━━━━━━━━━━━━━━┓
┃ NODE_TESTS_MOCKS ┃
┗━━━━━━━━━━━━━━━━━━━━━━┛
ALTERNATIVES ==> #See Node.js core
VERSION ==> #Part of Node.js core
[T.]mock 19.1.0*#MOCK_TRACKER
new MockTracker() 19.1.0*#MOCK_TRACKER
MOCKTRACKER.fn([FUNC] 19.1.0*#Def FUNC: noop
[, FUNC2][, OPTS])->MFUNC 19.1.0*#If FUNC2, call MCONTEXT.mockImplementation(FUNC2)
19.1.0*#OPTS:
19.1.0*# - times NUM (def: Infinity): after NUM times, call MCONTEXT.restore()
MOCKTRACKER.method 19.1.0*#Same but for a method. Directly modifies it
(OBJ, 'VAR'|SYM[, FUNC2] 19.1.0*#OPTS:
[, OPTS])->MFUNC 19.1.0*# - times NUM
19.1.0*# - getter|setter BOOL (def: false)
MOCKTRACKER.getter|setter
(...) 19.3.0*#Same as MOCKTRACKER.method(...) with OPTS.getter|setter true
MOCKTRACKER.restoreAll() 19.1.0*#Call all MCONTEXT.restore()
MOCKTRACKER.reset() 19.1.0*#Call MOCKTRACKER.restoreAll(), and undo all MOCKTRACKER.fn()
19.1.0*#T.mock.reset() is automatically called after each test
MFUNC.mock 19.1.0*#MCONTEXT
new MockFunctionContext() 19.1.0*#MCONTEXT
MCONTEXT.calls()->CALL_ARR 19.1.0*#Function calls
CALL.arguments 19.1.0*#ARR
CALL.this 19.1.0*#`this` VAL
CALL.result 19.1.0*#Return VAL
CALL.error 19.1.0*#ERROR thrown, or undefined
CALL.stack 19.1.0*#ERROR created during call, to get ERROR.stack
CALL.target 19.1.0*#new.target if FUNC is constructor, or undefined
MCONTEXT.callCount() 19.1.0*#Like MCONTEXT.calls.length
MCONTEXT.resetCalls() 19.3.0*#Reset MCONTEXT.calls
MCONTEXT.
mockImplementation
(FUNC2) 19.1.0*#Mocks implementation
MCONTEXT.
mockImplementationOnce 19.1.0*#Same but calls restore() right after the call.
(FUNC2[, NUM]) 19.1.0*#If NUM, only mock it for the call number NUM.
MCONTEXT.restore() 19.1.0*#Undo MCONTEXT.mockImplementation()