Skip to content

Latest commit

Β 

History

History
84 lines (54 loc) Β· 2.08 KB

assert.markdown

File metadata and controls

84 lines (54 loc) Β· 2.08 KB
Β 
Feb 29, 2012
Feb 29, 2012
1
# Assert
Oct 28, 2010
Oct 28, 2010
2
Mar 4, 2012
Mar 4, 2012
3
4
Stability: 5 - Locked
Oct 28, 2010
Oct 28, 2010
5
6
7
This module is used for writing unit tests for your applications, you can
access it with `require('assert')`.
Feb 29, 2012
Feb 29, 2012
8
## assert.fail(actual, expected, message, operator)
Oct 28, 2010
Oct 28, 2010
9
May 24, 2011
May 24, 2011
10
Throws an exception that displays the values for `actual` and `expected` separated by the provided operator.
Oct 28, 2010
Oct 28, 2010
11
Sep 25, 2014
Sep 25, 2014
12
## assert(value, message), assert.ok(value[, message])
Oct 28, 2010
Oct 28, 2010
13
Mar 12, 2012
Mar 12, 2012
14
Tests if value is truthy, it is equivalent to `assert.equal(true, !!value, message);`
Oct 28, 2010
Oct 28, 2010
15
Sep 25, 2014
Sep 25, 2014
16
## assert.equal(actual, expected[, message])
Oct 28, 2010
Oct 28, 2010
17
Nov 21, 2010
Nov 21, 2010
18
Tests shallow, coercive equality with the equal comparison operator ( `==` ).
Oct 28, 2010
Oct 28, 2010
19
Sep 25, 2014
Sep 25, 2014
20
## assert.notEqual(actual, expected[, message])
Oct 28, 2010
Oct 28, 2010
21
22
23
Tests shallow, coercive non-equality with the not equal comparison operator ( `!=` ).
Sep 25, 2014
Sep 25, 2014
24
## assert.deepEqual(actual, expected[, message])
Oct 28, 2010
Oct 28, 2010
25
26
27
Tests for deep equality.
Sep 25, 2014
Sep 25, 2014
28
## assert.notDeepEqual(actual, expected[, message])
Oct 28, 2010
Oct 28, 2010
29
Nov 21, 2010
Nov 21, 2010
30
Tests for any deep inequality.
Oct 28, 2010
Oct 28, 2010
31
Sep 25, 2014
Sep 25, 2014
32
## assert.strictEqual(actual, expected[, message])
Oct 28, 2010
Oct 28, 2010
33
Nov 21, 2010
Nov 21, 2010
34
Tests strict equality, as determined by the strict equality operator ( `===` )
Oct 28, 2010
Oct 28, 2010
35
Sep 25, 2014
Sep 25, 2014
36
## assert.notStrictEqual(actual, expected[, message])
Oct 28, 2010
Oct 28, 2010
37
Nov 21, 2010
Nov 21, 2010
38
Tests strict non-equality, as determined by the strict not equal operator ( `!==` )
Oct 28, 2010
Oct 28, 2010
39
Sep 25, 2014
Sep 25, 2014
40
## assert.throws(block[, error]\[, message])
Oct 28, 2010
Oct 28, 2010
41
Feb 23, 2014
Feb 23, 2014
42
Expects `block` to throw an error. `error` can be constructor, `RegExp` or
Dec 2, 2010
Dec 2, 2010
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
validation function.
Validate instanceof using constructor:
assert.throws(
function() {
throw new Error("Wrong value");
},
Error
);
Validate error message using RegExp:
assert.throws(
function() {
throw new Error("Wrong value");
},
/value/
);
Custom error validation:
assert.throws(
function() {
throw new Error("Wrong value");
},
function(err) {
Dec 21, 2010
Dec 21, 2010
70
71
if ( (err instanceof Error) && /value/.test(err) ) {
return true;
Dec 2, 2010
Dec 2, 2010
72
73
74
75
}
},
"unexpected error"
);
Oct 28, 2010
Oct 28, 2010
76
Sep 25, 2014
Sep 25, 2014
77
## assert.doesNotThrow(block[, message])
Oct 28, 2010
Oct 28, 2010
78
Feb 23, 2014
Feb 23, 2014
79
Expects `block` not to throw an error, see `assert.throws` for details.
Oct 28, 2010
Oct 28, 2010
80
Feb 29, 2012
Feb 29, 2012
81
## assert.ifError(value)
Oct 28, 2010
Oct 28, 2010
82
Nov 18, 2010
Nov 18, 2010
83
84
Tests if value is not a false value, throws if it is a true value. Useful when
testing the first argument, `error` in callbacks.