@@ -348,37 +348,44 @@ assert.throws(makeBlock(thrower, a.AssertionError));
348
348
assert . throws ( makeBlock ( thrower , TypeError ) ) ;
349
349
350
350
// when passing a type, only catch errors of the appropriate type
351
- let threw = false ;
352
- try {
353
- a . throws ( makeBlock ( thrower , TypeError ) , a . AssertionError ) ;
354
- } catch ( e ) {
355
- threw = true ;
356
- assert . ok ( e instanceof TypeError , 'type' ) ;
351
+ {
352
+ let threw = false ;
353
+ try {
354
+ a . throws ( makeBlock ( thrower , TypeError ) , a . AssertionError ) ;
355
+ } catch ( e ) {
356
+ threw = true ;
357
+ assert . ok ( e instanceof TypeError , 'type' ) ;
358
+ }
359
+ assert . strictEqual ( true , threw ,
360
+ 'a.throws with an explicit error is eating extra errors' ,
361
+ a . AssertionError ) ;
357
362
}
358
- assert . strictEqual ( true , threw ,
359
- 'a.throws with an explicit error is eating extra errors' ,
360
- a . AssertionError ) ;
361
- threw = false ;
362
363
363
364
// doesNotThrow should pass through all errors
364
- try {
365
- a . doesNotThrow ( makeBlock ( thrower , TypeError ) , a . AssertionError ) ;
366
- } catch ( e ) {
367
- threw = true ;
368
- assert . ok ( e instanceof TypeError ) ;
365
+ {
366
+ let threw = false ;
367
+ try {
368
+ a . doesNotThrow ( makeBlock ( thrower , TypeError ) , a . AssertionError ) ;
369
+ } catch ( e ) {
370
+ threw = true ;
371
+ assert . ok ( e instanceof TypeError ) ;
372
+ }
373
+ assert . strictEqual ( true , threw , 'a.doesNotThrow with an explicit error is ' +
374
+ 'eating extra errors' ) ;
369
375
}
370
- assert . strictEqual ( true , threw , 'a.doesNotThrow with an explicit error is ' +
371
- 'eating extra errors' ) ;
372
376
373
377
// key difference is that throwing our correct error makes an assertion error
374
- try {
375
- a . doesNotThrow ( makeBlock ( thrower , TypeError ) , TypeError ) ;
376
- } catch ( e ) {
377
- threw = true ;
378
- assert . ok ( e instanceof a . AssertionError ) ;
378
+ {
379
+ let threw = false ;
380
+ try {
381
+ a . doesNotThrow ( makeBlock ( thrower , TypeError ) , TypeError ) ;
382
+ } catch ( e ) {
383
+ threw = true ;
384
+ assert . ok ( e instanceof a . AssertionError ) ;
385
+ }
386
+ assert . strictEqual ( true , threw ,
387
+ 'a.doesNotThrow is not catching type matching errors' ) ;
379
388
}
380
- assert . strictEqual ( true , threw ,
381
- 'a.doesNotThrow is not catching type matching errors' ) ;
382
389
383
390
assert . throws ( function ( ) { assert . ifError ( new Error ( 'test error' ) ) ; } ) ;
384
391
assert . doesNotThrow ( function ( ) { assert . ifError ( null ) ; } ) ;
@@ -390,18 +397,20 @@ assert.throws(() => {
390
397
'a.doesNotThrow ignores user message' ) ;
391
398
392
399
// make sure that validating using constructor really works
393
- threw = false ;
394
- try {
395
- assert . throws (
396
- function ( ) {
397
- throw ( { } ) ; // eslint-disable-line no-throw-literal
398
- } ,
399
- Array
400
- ) ;
401
- } catch ( e ) {
402
- threw = true ;
400
+ {
401
+ let threw = false ;
402
+ try {
403
+ assert . throws (
404
+ function ( ) {
405
+ throw ( { } ) ; // eslint-disable-line no-throw-literal
406
+ } ,
407
+ Array
408
+ ) ;
409
+ } catch ( e ) {
410
+ threw = true ;
411
+ }
412
+ assert . ok ( threw , 'wrong constructor validation' ) ;
403
413
}
404
- assert . ok ( threw , 'wrong constructor validation' ) ;
405
414
406
415
// use a RegExp to validate error message
407
416
a . throws ( makeBlock ( thrower , TypeError ) , / t e s t / ) ;
@@ -414,26 +423,28 @@ a.throws(makeBlock(thrower, TypeError), function(err) {
414
423
} ) ;
415
424
416
425
// https://github.com/nodejs/node/issues/3188
417
- threw = false ;
426
+ {
427
+ let threw = false ;
418
428
419
- let AnotherErrorType ;
420
- try {
421
- const ES6Error = class extends Error { } ;
429
+ let AnotherErrorType ;
430
+ try {
431
+ const ES6Error = class extends Error { } ;
422
432
423
- AnotherErrorType = class extends Error { } ;
433
+ AnotherErrorType = class extends Error { } ;
424
434
425
- const functionThatThrows = function ( ) {
426
- throw new AnotherErrorType ( 'foo' ) ;
427
- } ;
435
+ const functionThatThrows = function ( ) {
436
+ throw new AnotherErrorType ( 'foo' ) ;
437
+ } ;
428
438
429
- assert . throws ( functionThatThrows , ES6Error ) ;
430
- } catch ( e ) {
431
- threw = true ;
432
- assert ( e instanceof AnotherErrorType ,
433
- `expected AnotherErrorType, received ${ e } ` ) ;
434
- }
439
+ assert . throws ( functionThatThrows , ES6Error ) ;
440
+ } catch ( e ) {
441
+ threw = true ;
442
+ assert ( e instanceof AnotherErrorType ,
443
+ `expected AnotherErrorType, received ${ e } ` ) ;
444
+ }
435
445
436
- assert . ok ( threw ) ;
446
+ assert . ok ( threw ) ;
447
+ }
437
448
438
449
// https://github.com/nodejs/node/issues/6416
439
450
// Make sure circular refs don't throw.
@@ -515,15 +526,18 @@ testAssertionMessage({a: NaN, b: Infinity, c: -Infinity},
515
526
'{ a: NaN, b: Infinity, c: -Infinity }' ) ;
516
527
517
528
// #2893
518
- try {
519
- assert . throws ( function ( ) {
520
- assert . ifError ( null ) ;
521
- } ) ;
522
- } catch ( e ) {
523
- threw = true ;
524
- assert . strictEqual ( e . message , 'Missing expected exception..' ) ;
529
+ {
530
+ let threw = false ;
531
+ try {
532
+ assert . throws ( function ( ) {
533
+ assert . ifError ( null ) ;
534
+ } ) ;
535
+ } catch ( e ) {
536
+ threw = true ;
537
+ assert . strictEqual ( e . message , 'Missing expected exception..' ) ;
538
+ }
539
+ assert . ok ( threw ) ;
525
540
}
526
- assert . ok ( threw ) ;
527
541
528
542
// #5292
529
543
try {
0 commit comments