@@ -655,40 +655,46 @@ try {
655
655
'Message incorrectly marked as generated' ) ;
656
656
}
657
657
658
- // Verify that throws() and doesNotThrow() throw on non-function block
659
- function testBlockTypeError ( method , block ) {
660
- let threw = true ;
661
-
662
- try {
663
- method ( block ) ;
664
- threw = false ;
665
- } catch ( e ) {
666
- assert . strictEqual ( e . toString ( ) ,
667
- 'TypeError: "block" argument must be a function' ) ;
668
- }
658
+ {
659
+ // Verify that throws() and doesNotThrow() throw on non-function block
660
+ const validationFunction = common . expectsError ( {
661
+ code : 'ERR_INVALID_ARG_TYPE' ,
662
+ type : TypeError
663
+ } ) ;
664
+
665
+ const testBlockTypeError = ( method , block ) => {
666
+ let threw = true ;
667
+
668
+ try {
669
+ method ( block ) ;
670
+ threw = false ;
671
+ } catch ( e ) {
672
+ validationFunction ( e ) ;
673
+ }
674
+
675
+ assert . ok ( threw ) ;
676
+ } ;
669
677
670
- assert . ok ( threw ) ;
678
+ testBlockTypeError ( assert . throws , 'string' ) ;
679
+ testBlockTypeError ( assert . doesNotThrow , 'string' ) ;
680
+ testBlockTypeError ( assert . throws , 1 ) ;
681
+ testBlockTypeError ( assert . doesNotThrow , 1 ) ;
682
+ testBlockTypeError ( assert . throws , true ) ;
683
+ testBlockTypeError ( assert . doesNotThrow , true ) ;
684
+ testBlockTypeError ( assert . throws , false ) ;
685
+ testBlockTypeError ( assert . doesNotThrow , false ) ;
686
+ testBlockTypeError ( assert . throws , [ ] ) ;
687
+ testBlockTypeError ( assert . doesNotThrow , [ ] ) ;
688
+ testBlockTypeError ( assert . throws , { } ) ;
689
+ testBlockTypeError ( assert . doesNotThrow , { } ) ;
690
+ testBlockTypeError ( assert . throws , / f o o / ) ;
691
+ testBlockTypeError ( assert . doesNotThrow , / f o o / ) ;
692
+ testBlockTypeError ( assert . throws , null ) ;
693
+ testBlockTypeError ( assert . doesNotThrow , null ) ;
694
+ testBlockTypeError ( assert . throws , undefined ) ;
695
+ testBlockTypeError ( assert . doesNotThrow , undefined ) ;
671
696
}
672
697
673
- testBlockTypeError ( assert . throws , 'string' ) ;
674
- testBlockTypeError ( assert . doesNotThrow , 'string' ) ;
675
- testBlockTypeError ( assert . throws , 1 ) ;
676
- testBlockTypeError ( assert . doesNotThrow , 1 ) ;
677
- testBlockTypeError ( assert . throws , true ) ;
678
- testBlockTypeError ( assert . doesNotThrow , true ) ;
679
- testBlockTypeError ( assert . throws , false ) ;
680
- testBlockTypeError ( assert . doesNotThrow , false ) ;
681
- testBlockTypeError ( assert . throws , [ ] ) ;
682
- testBlockTypeError ( assert . doesNotThrow , [ ] ) ;
683
- testBlockTypeError ( assert . throws , { } ) ;
684
- testBlockTypeError ( assert . doesNotThrow , { } ) ;
685
- testBlockTypeError ( assert . throws , / f o o / ) ;
686
- testBlockTypeError ( assert . doesNotThrow , / f o o / ) ;
687
- testBlockTypeError ( assert . throws , null ) ;
688
- testBlockTypeError ( assert . doesNotThrow , null ) ;
689
- testBlockTypeError ( assert . throws , undefined ) ;
690
- testBlockTypeError ( assert . doesNotThrow , undefined ) ;
691
-
692
698
// https://github.com/nodejs/node/issues/3275
693
699
// eslint-disable-next-line no-throw-literal
694
700
assert . throws ( ( ) => { throw 'error' ; } , ( err ) => err === 'error' ) ;
0 commit comments