-
Notifications
You must be signed in to change notification settings - Fork 16
/
node_tap_assertions.javascript.txt
157 lines (111 loc) · 8.85 KB
/
node_tap_assertions.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
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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
NODE_TAP_ASSERTIONS
ALTERNATIVES ==> #See chai doc
VERSION ==> #Part of node-tap (see its doc)
/=+===============================+=\
/ : : \
)==: COMMON :==(
\ :_______________________________: /
\=+===============================+=/
EXCEPTIONS ==> #Assertions only report: they do not throw (i.e. control flow continues)
#This helps reporting several failed assertions per test
#However this means following assertions might crash: they will be handled but might clutter
#test output (where only first failed assertion might be relevant)
TEST.*()->BOOL #All assertions return BOOL (or PROMISE for TEST.resolve*|rejects())
TEST.passing()->BOOL #False if a previous assertion has failed
TEST.* #Can be passed for all assertion functions as last arguments.
(...[, 'ASSERT_TITLE'][, AOPTS]) #Def 'ASSERT_TITLE':
# - TEST.pass|fail|skip(): '(unnamed test)'
# - TEST.threw|error(): ERROR.message
# - TEST.throws|doesNotThrow|rejects|resolve*(): FUNC.name
# - custom assertion: none
# - others: 'should|expect ...'
/=+===============================+=\
/ : : \
)==: GENERIC :==(
\ :_______________________________: /
\=+===============================+=/
TEST.pass() #
TEST.fail() #
TEST.threw(ERROR) #Like TEST.fail() but using information from ERROR:
# - 'ASSERT_TITLE': ERROR.message
# - stack|at|source: ERROR.stack
# - any ERROR.*: as is (stringified with UTIL.inspect())
TEST.equal(VAL, VAL2) #===
#Aliases: TEST.equals|isEqual|is|strictEqual[s]|strictIs|isStrict[ly]()
TEST.notEqual(VAL, VAL2) #!==
#Aliases: TEST.notEquals|isNotEqual|doesNotEqual|[is]inequal|isNot|notStrictEqual[s]()
TEST.strictSame(VAL, VAL2) #Deep ===
#Aliases: TEST.strictDeepEqual[s]|strictEquivalent|sameStrict|deepIs|isDeep[ly]()
TEST.strictNotSame(VAL, VAL2) #Deep !==
#Aliases: TEST.strictInequivalent|strictDeepInequal[s]|notSameStrict|deepNot|notDeeply|notStrictSame()
TEST.same(VAL, VAL2) #Deep ==
#Aliases: TEST.deepEqual[s]|looseEqual[s]|equivalent|isLoose|looseIs()
TEST.notSame(VAL, VAL2) #Deep !=
#Aliases: TEST.notLoose|looseNot|notDeep|inequivalent|looseInequal|deepInequal()
TEST.error(ERROR) #instanceof Error
#Aliases: TEST.ifErr[or]()
TEST.hasStrict(VAL, VAL2) #Deep ==
TEST.match(VAL, VAL2) #Deep ==
#Aliases: TEST.has[Fields]|matches|similar|[is]like|include[s]|contains()
TEST.match(OBJ, OBJ2) #Deep TEST.match()
TEST.notMatch(VAL, VAL2) #Inverse of TEST.match()
#Aliases: TEST.[is]dissimilar|unsimilar|[is]notSimilar|[is]unlike|[is]notLike|doesNotHave()
TEST.match(VAL, TYPE) #instanceof TYPE (can use String|Boolean|... for simple types)
TEST.type #typeof VAL === 'TYPEOF' || instanceof TYPE|'TYPE'
(VAL, 'TYPEOF'|'TYPE'|TYPE) #Aliases: TEST.isA()
/=+===============================+=\
/ : : \
)==: BOOLEAN :==(
\ :_______________________________: /
\=+===============================+=/
TEST.ok(VAL) #== true
#Aliases: TEST.true|assert()
TEST.notOk(VAL) #== false
#Aliases: TEST.false|assertNot()
/=+===============================+=\
/ : : \
)==: STRING :==(
\ :_______________________________: /
\=+===============================+=/
TEST.match(STR, REGEXP) #REGEXP.test()
TEST.match(STR, STR2) #STR.includes(STR2)
/=+===============================+=\
/ : : \
)==: FUNCTION :==(
\ :_______________________________: /
\=+===============================+=/
TEST.throws #FUNC() throws, and TEST.match(ERROR, ERROR2)
(FUNC[, ERROR2][, STR])->ERROR #STR is ERROR.message
#Aliases: TEST.throw()
TEST.doesNotThrow #Inverse
(FUNC[, ERROR2][, STR]) #Aliases: TEST.notThrow()
TEST.expectUncaughtException
(FUNC[, ERROR2][, STR]) #Test should throw an uncaught exception
/=+===============================+=\
/ : : \
)==: PROMISE :==(
\ :_______________________________: /
\=+===============================+=/
TEST.rejects(PROMISE[()][, VAL]) #PROMISE rejected with VAL2, and TEST.match(VAL2, VAL)
TEST.resolveMatch
(PROMISE[()][, VAL]) #PROMISE resolved with VAL2, and TEST.match(VAL2, VAL)
TEST.resolves(PROMISE[()]) #PROMISE resolved
TEST.rejects|resolve*() #Actually create a sub-TEST, i.e. behave like TEST.test()
/=+===============================+=\
/ : : \
)==: EVENTS :==(
\ :_______________________________: /
\=+===============================+=/
TEST.emits
(EVENTEMITTER, 'EVENT'[, VAL]) #Calls EVENTEMITTER.emit('EVENT'[, VAL]) before end of test
/=+===============================+=\
/ : : \
)==: EXTENSIONS :==(
\ :_______________________________: /
\=+===============================+=/
Test.prototype.addAssert
('FUNC', NUM,
FUNC(ARGS..., 'ASSERT_TITLE',OBJ)#Custom assertion
->BOOL) #NUM is ARGS length