MCPcopy Index your code
hub / github.com/caolan/nodeunit / _throws

Function _throws

lib/assert.js:317–346  ·  view source on GitHub ↗
(shouldThrow, block, expected, message)

Source from the content-addressed store, hash-verified

315}
316
317function _throws(shouldThrow, block, expected, message) {
318 var actual;
319
320 if (typeof expected === 'string') {
321 message = expected;
322 expected = null;
323 }
324
325 try {
326 block();
327 } catch (e) {
328 actual = e;
329 }
330
331 message = (expected && expected.name ? ' (' + expected.name + ').' : '.') +
332 (message ? ' ' + message : '.');
333
334 if (shouldThrow && !actual) {
335 fail('Missing expected exception' + message);
336 }
337
338 if (!shouldThrow && expectedException(actual, expected)) {
339 fail('Got unwanted exception' + message);
340 }
341
342 if ((shouldThrow && actual && expected &&
343 !expectedException(actual, expected)) || (!shouldThrow && actual)) {
344 throw actual;
345 }
346}
347
348// 11. Expected to throw an error:
349// assert.throws(block, Error_opt, message_opt);

Callers

nothing calls this directly

Calls 2

expectedExceptionFunction · 0.85
failFunction · 0.70

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…