MCPcopy Index your code
hub / github.com/nodejs/node / assertThrows

Function assertThrows

deps/v8/test/intl/assert.js:157–177  ·  view source on GitHub ↗

* Runs code() and asserts that it throws the specified exception.

(code, type_opt, cause_opt)

Source from the content-addressed store, hash-verified

155 * Runs code() and asserts that it throws the specified exception.
156 */
157function assertThrows(code, type_opt, cause_opt) {
158 try {
159 if (typeof code == 'function') {
160 code();
161 } else {
162 eval(code);
163 }
164 } catch (e) {
165 if (typeof type_opt == 'function') {
166 assertInstanceof(e, type_opt);
167 }
168 if (arguments.length >= 3) {
169 assertEquals(cause_opt, e.message, 'thrown exception type mismatch');
170 }
171 // Success.
172 return;
173 }
174 var expected = arguments.length >= 3 ? cause_opt :
175 typeof type_opt == 'function' ? type_opt : 'any exception';
176 fail(expected, 'no exception', 'expected thrown exception');
177}
178
179
180/**

Callers 15

regress-917151.jsFile · 0.70
bad-target.jsFile · 0.70
regress-9747.jsFile · 0.70
regress-903566.jsFile · 0.70
regress-10613.jsFile · 0.70
regress-4870.jsFile · 0.70
regress-10438.jsFile · 0.70
regress-1427932.jsFile · 0.70
regress-9464.jsFile · 0.70

Calls 5

assertInstanceofFunction · 0.85
assertEqualsFunction · 0.70
failFunction · 0.70
codeFunction · 0.50
evalFunction · 0.50

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…