File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -56,8 +56,8 @@ const {
5656 once : runOnce ,
5757 setOwnProperty,
5858} = require ( 'internal/util' ) ;
59- const { isDeepStrictEqual } = require ( 'internal/util/comparisons ' ) ;
60- const { isPromise, isRegExp } = require ( 'internal/util/types' ) ;
59+ const assert = require ( 'assert ' ) ;
60+ const { isPromise } = require ( 'internal/util/types' ) ;
6161const {
6262 validateAbortSignal,
6363 validateFunction,
@@ -959,29 +959,15 @@ class Test extends AsyncResource {
959959 if ( typeof this . expectFailure === 'object' &&
960960 this . expectFailure . with !== undefined ) {
961961 const { with : validation } = this . expectFailure ;
962- let match = false ;
963-
964- if ( isRegExp ( validation ) ) {
965- match = RegExpPrototypeExec ( validation , err . message ) !== null ;
966- } else if ( typeof validation === 'object' && validation !== null ) {
967- match = true ;
968- for ( const prop in validation ) {
969- if ( ! isDeepStrictEqual ( err [ prop ] , validation [ prop ] ) ) {
970- match = false ;
971- break ;
972- }
973- }
974- } else if ( validation === err ) {
975- match = true ;
976- }
977-
978- if ( ! match ) {
962+ try {
963+ assert . throws ( ( ) => { throw err ; } , validation ) ;
964+ } catch ( e ) {
979965 this . passed = false ;
980966 this . error = new ERR_TEST_FAILURE (
981967 'The test failed, but the error did not match the expected validation' ,
982968 kTestCodeFailure ,
983969 ) ;
984- this . error . cause = err ;
970+ this . error . cause = e ;
985971 return ;
986972 }
987973 }
Original file line number Diff line number Diff line change @@ -21,6 +21,10 @@ if (process.env.CHILD_PROCESS === 'true') {
2121 assert . fail ( 'boom' ) ;
2222 } ) ;
2323
24+ test ( 'fail with validation class' , { expectFailure : { with : assert . AssertionError } } , ( ) => {
25+ assert . fail ( 'boom' ) ;
26+ } ) ;
27+
2428 test ( 'fail with validation error (wrong error)' , { expectFailure : { with : / b a n g / } } , ( ) => {
2529 assert . fail ( 'boom' ) ; // Should result in real failure because error doesn't match
2630 } ) ;
You can’t perform that action at this time.
0 commit comments