File tree Expand file tree Collapse file tree 2 files changed +10
-20
lines changed
Expand file tree Collapse file tree 2 files changed +10
-20
lines changed 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,
@@ -958,29 +958,15 @@ class Test extends AsyncResource {
958958 if ( typeof this . expectFailure === 'object' &&
959959 this . expectFailure . with !== undefined ) {
960960 const { with : validation } = this . expectFailure ;
961- let match = false ;
962-
963- if ( isRegExp ( validation ) ) {
964- match = RegExpPrototypeExec ( validation , err . message ) !== null ;
965- } else if ( typeof validation === 'object' && validation !== null ) {
966- match = true ;
967- for ( const prop in validation ) {
968- if ( ! isDeepStrictEqual ( err [ prop ] , validation [ prop ] ) ) {
969- match = false ;
970- break ;
971- }
972- }
973- } else if ( validation === err ) {
974- match = true ;
975- }
976-
977- if ( ! match ) {
961+ try {
962+ assert . throws ( ( ) => { throw err ; } , validation ) ;
963+ } catch ( e ) {
978964 this . passed = false ;
979965 this . error = new ERR_TEST_FAILURE (
980966 'The test failed, but the error did not match the expected validation' ,
981967 kTestCodeFailure ,
982968 ) ;
983- this . error . cause = err ;
969+ this . error . cause = e ;
984970 return ;
985971 }
986972 }
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