Skip to content

Commit e8bb02f

Browse files
committed
docs: Clarify assert.doesNotThrow behavior
The documentation for assert.doesNotThrow now reflects all the inputs the function accepts, as well as the errors thrown for each combination of parameter types.
1 parent a1949e8 commit e8bb02f

File tree

1 file changed

+20
-2
lines changed

1 file changed

+20
-2
lines changed

doc/api/assert.markdown

+20-2
Original file line numberDiff line numberDiff line change
@@ -85,9 +85,27 @@ Custom error validation:
8585
"unexpected error"
8686
);
8787

88-
## assert.doesNotThrow(block[, message])
88+
## assert.doesNotThrow(block[, error][, message])
8989

90-
Expects `block` not to throw an error, see `assert.throws` for details.
90+
Expects `block` not to throw an error. See [assert.throws()](#assert_assert_throws_block_error_message) for more details.
91+
92+
If `block` throws an error and if it is of a different type from `error`, the thrown error will get propagated back to the caller. The following call will throw the `TypeError`, since we're not matching the error types in the assertion.
93+
94+
assert.doesNotThrow(
95+
function() {
96+
throw new TypeError("Wrong value");
97+
},
98+
SyntaxError
99+
);
100+
101+
In case `error` matches with the error thrown by `block`, an `AssertionError` is thrown instead.
102+
103+
assert.doesNotThrow(
104+
function() {
105+
throw new TypeError("Wrong value");
106+
},
107+
TypeError
108+
);
91109

92110
## assert.ifError(value)
93111

0 commit comments

Comments
 (0)