-
Notifications
You must be signed in to change notification settings - Fork 16
/
deno_mock.deno.txt
85 lines (59 loc) · 4.87 KB
/
deno_mock.deno.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
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
DENO_MOCK
ALTERNATIVES ==> #See Sinon
VERSION ==> #Part of Deno test (see its doc)
std/testing/mock.ts #Entrypoint (std library)
/=+===============================+=\
/ : : \
)==: SPIES :==(
\ :_______________________________: /
\=+===============================+=/
spy()->SPY
spy([FUNC])->SPY #Spy on FUNC (def: noop) without changing it
spy(OBJ, 'FUNC')->SPY #Spy on OBJ.FUNC and sets it to SPY
SPY.original #Underlying FUNC
SPY.fake #Mock FUNC2 (with stub())
SPY.restore() #Remove spying
SPY.restored #BOOL. True if SPY.restore() called
SPY.calls #CALL_ARR made while spying
CALL.args #ARR
CALL.self #VAL used as this
CALL.returned #VAL returned
CALL.error #VAL thrown (if any)
/=+===============================+=\
/ : : \
)==: STUBS :==(
\ :_______________________________: /
\=+===============================+=/
stub(OBJ, 'FUNC'[, FUNC2])->SPY #Like spy(...) but mocks with FUNC2 (def: noop)
returnsArg(NUM)->FUNC #Returns a FUNC() that returns argument number NUM
returnsArgs([NUM[, NUM2]])->FUNC #Returns a FUNC() that returns arguments ARR.
#NUM[2] is start|end (def: all args)
returnsThis(ITERABLE)->FUNC #Returns a FUNC() that returns `this`
returnsNext(ITERABLE)->FUNC #Returns a FUNC() where each call returns ITERABLE.next()
resolvesNext(ASYNC_ITERABLE)->FUNC#Same but async
/=+===============================+=\
/ : : \
)==: ASSERTIONS :==(
\ :_______________________________: /
\=+===============================+=/
assertSpyCalls(SPY, NUM) #Asserts that SPY.calls.length === NUM
assertSpyCallArg
(SPY, NUM, NUM2, VAL)->VAL #Asserts that SPY.calls[NUM].args[NUM2] is VAL, using assertEquals()
assertSpyCallArgs
(SPY, NUM[, NUM2[, NUM3]], ARR) #Asserts that SPY.calls[NUM].args match ARR, using assertEquals()
->ARR #NUM2|3 is start|end (def: all args)
assertSpyCall(SPY, NUM[, EXPECT]) #Asserts that SPY.calls[NUM] matches EXPECT, using assertEquals()
assertSpyCallAsync(...)->> #Same but async
EXPECT.args|self|returned #Like CALL.*
EXPECT.error.Class #ERROR_CLASS
EXPECT.error.msgIncludes #'MESSAGE'
/=+===============================+=\
/ : : \
)==: SANDBOX :==(
\ :_______________________________: /
\=+===============================+=/
mockSession()->ID #
restore([ID]) #Call SPY.restore() on all SPYs created since mockSession() (def: all)
mockSession[Async](FUNC)->FUNC #Make FUNC(...) call restore() at the end