@@ -28,6 +28,7 @@ const {
2828const { codes : {
2929 ERR_AMBIGUOUS_ARGUMENT ,
3030 ERR_INVALID_ARG_TYPE ,
31+ ERR_INVALID_ARG_VALUE ,
3132 ERR_INVALID_RETURN_VALUE
3233} } = require ( 'internal/errors' ) ;
3334const { AssertionError, errorCache } = require ( 'internal/assert' ) ;
@@ -414,12 +415,6 @@ function expectedException(actual, expected, msg) {
414415 ) ;
415416 }
416417
417- // TODO: Disallow primitives as error argument.
418- // This is here to prevent a breaking change.
419- if ( typeof expected !== 'object' ) {
420- return true ;
421- }
422-
423418 // Handle primitives properly.
424419 if ( typeof actual !== 'object' || actual === null ) {
425420 const err = new AssertionError ( {
@@ -438,6 +433,9 @@ function expectedException(actual, expected, msg) {
438433 // as well.
439434 if ( expected instanceof Error ) {
440435 keys . push ( 'name' , 'message' ) ;
436+ } else if ( keys . length === 0 ) {
437+ throw new ERR_INVALID_ARG_VALUE ( 'error' ,
438+ expected , 'may not be an empty object' ) ;
441439 }
442440 for ( const key of keys ) {
443441 if ( typeof actual [ key ] === 'string' &&
@@ -527,6 +525,12 @@ function expectsError(stackStartFn, actual, error, message) {
527525 }
528526 message = error ;
529527 error = undefined ;
528+ } else if ( error != null &&
529+ typeof error !== 'object' &&
530+ typeof error !== 'function' ) {
531+ throw new ERR_INVALID_ARG_TYPE ( 'error' ,
532+ [ 'Object' , 'Error' , 'Function' , 'RegExp' ] ,
533+ error ) ;
530534 }
531535
532536 if ( actual === NO_EXCEPTION_SENTINEL ) {
0 commit comments