-
Notifications
You must be signed in to change notification settings - Fork 16
/
node_assert.node.txt
116 lines (79 loc) · 6.37 KB
/
node_assert.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
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
NODE_ASSERT
ALTERNATIVES ==> #See chai
VERSION ==> #Part of Node.js core
/=+===============================+=\
/ : : \
)==: BASE :==(
\ :_______________________________: /
\=+===============================+=/
T.assert.* 22.2.0*#Same as ASSERT.* except works with T.plan(NUM)
ASSERT #Throws ERROR or ASSERTIONERROR with message 'MESSAGE' if fails.
ASSERT.*(..., 'MESSAGE'|ERROR) #Can be always passed as last argument (except ifError()). Def:
# - [not]equal|ok(): 'VAL ==|!= VAL2'
# - [not]DeepEqual(): 'VAL [not]DeepEqual VAL2'
# - fail(): 'Failed'
# - strictEqual(): diff
# - others: sentence
ASSERTIONERROR.actual|expected #VAL
#With *equal|ok|ifError()
#Does a colored diff
#Only actual with *throws|*rejects()
ASSERTIONERROR.operator #'==' (equal|ok()) or '!=' (notEqual()), 'fail' (fail()),
#'throw|doesNotThrow|reject|doesNotReject', 'FUNC' (others)
ASSERT.strict.*(...) #Same as ASSERT.*(...) except:
# - use === instead of ==
# - when arguments are OBJ, prints an OBJ diff instead of showing them in full
require('assert/strict') 15.0.0*#Same as ASSERT.strict
/=+===============================+=\
/ : : \
)==: GENERIC :==(
\ :_______________________________: /
\=+===============================+=/
ASSERT.fail() #Always fails
ASSERT.[not]equal(VAL, VAL2) #VAL == VAL2
14*#or both NaN
ASSERT.[not]strictEqual
(VAL, VAL2) #Object.is(VAL, VAL2)
ASSERT.[not]deepStrictEqual
(VAL, VAL2) #UTIL.isDeepStrictEqual()
/=+===============================+=\
/ : : \
)==: NULL :==(
\ :_______________________________: /
\=+===============================+=/
ASSERT.ifError(VAL) #VAL === null
/=+===============================+=\
/ : : \
)==: BOOLEAN :==(
\ :_______________________________: /
\=+===============================+=/
ASSERT[.ok](VAL) #VAL === true
/=+===============================+=\
/ : : \
)==: STRING :==(
\ :_______________________________: /
\=+===============================+=/
ASSERT.[doesNot]match
(STR, REGEXP) #REGEXP.test(STR)
/=+===============================+=\
/ : : \
)==: FUNCTION :==(
\ :_______________________________: /
\=+===============================+=/
ASSERT.throws|doesNotThrow #Function throws
(FUNC()[, VAL]) #VAL can be:
# - TYPE|ERROR: instanceof
# - FUNC(ERROR)->BOOL
# - REGEXP: against ERROR.message
# - OBJ: deep ==
/=+===============================+=\
/ : : \
)==: PROMISE :==(
\ :_______________________________: /
\=+===============================+=/
ASSERT.rejects|doesNotReject #PROMISE rejection
(PROMISE[()][, VAL])->PROMISE2 #Fails if FUNC()->PROMISE throws before returning the PROMISE
#Fails if not using a PROMISE[()]
#PROMISE2 is resolved if test passed