@@ -31,6 +31,8 @@ const { inspect } = require('util');
31
31
32
32
const assert = module . exports = ok ;
33
33
34
+ const NO_EXCEPTION_SENTINEL = { } ;
35
+
34
36
// All of the following functions must throw an AssertionError
35
37
// when a corresponding condition is not met, with a message that
36
38
// may be undefined if not provided. All assertion methods provide
@@ -256,6 +258,7 @@ function getActual(block) {
256
258
} catch ( e ) {
257
259
return e ;
258
260
}
261
+ return NO_EXCEPTION_SENTINEL ;
259
262
}
260
263
261
264
// Expected to throw an error.
@@ -273,7 +276,7 @@ assert.throws = function throws(block, error, message) {
273
276
error = null ;
274
277
}
275
278
276
- if ( actual === undefined ) {
279
+ if ( actual === NO_EXCEPTION_SENTINEL ) {
277
280
let details = '' ;
278
281
if ( error && error . name ) {
279
282
details += ` (${ error . name } )` ;
@@ -294,7 +297,7 @@ assert.throws = function throws(block, error, message) {
294
297
295
298
assert . doesNotThrow = function doesNotThrow ( block , error , message ) {
296
299
const actual = getActual ( block ) ;
297
- if ( actual === undefined )
300
+ if ( actual === NO_EXCEPTION_SENTINEL )
298
301
return ;
299
302
300
303
if ( typeof error === 'string' ) {
@@ -308,7 +311,7 @@ assert.doesNotThrow = function doesNotThrow(block, error, message) {
308
311
actual,
309
312
expected : error ,
310
313
operator : 'doesNotThrow' ,
311
- message : `Got unwanted exception${ details } \n${ actual . message } ` ,
314
+ message : `Got unwanted exception${ details } \n${ actual && actual . message } ` ,
312
315
stackStartFn : doesNotThrow
313
316
} ) ;
314
317
}
0 commit comments