File tree 2 files changed +12
-1
lines changed
2 files changed +12
-1
lines changed Original file line number Diff line number Diff line change @@ -398,7 +398,10 @@ function runCallChecks(exitCode) {
398
398
399
399
400
400
exports . mustCall = function ( fn , expected ) {
401
- if ( typeof expected !== 'number' ) expected = 1 ;
401
+ if ( expected === undefined )
402
+ expected = 1 ;
403
+ else if ( typeof expected !== 'number' )
404
+ throw new TypeError ( `Invalid expected value: ${ expected } ` ) ;
402
405
403
406
const context = {
404
407
expected : expected ,
Original file line number Diff line number Diff line change @@ -5,3 +5,11 @@ var assert = require('assert');
5
5
common . globalCheck = false ;
6
6
global . gc = 42 ; // Not a valid global unless --expose_gc is set.
7
7
assert . deepStrictEqual ( common . leakedGlobals ( ) , [ 'gc' ] ) ;
8
+
9
+ assert . throws ( function ( ) {
10
+ common . mustCall ( function ( ) { } , 'foo' ) ;
11
+ } , / ^ T y p e E r r o r : I n v a l i d e x p e c t e d v a l u e : f o o $ / ) ;
12
+
13
+ assert . throws ( function ( ) {
14
+ common . mustCall ( function ( ) { } , / f o o / ) ;
15
+ } , / ^ T y p e E r r o r : I n v a l i d e x p e c t e d v a l u e : \/ f o o \/ $ / ) ;
You can’t perform that action at this time.
0 commit comments