File tree Expand file tree Collapse file tree 2 files changed +12
-1
lines changed Expand file tree Collapse file tree 2 files changed +12
-1
lines changed Original file line number Diff line number Diff line change @@ -397,7 +397,10 @@ function runCallChecks(exitCode) {
397
397
398
398
399
399
exports . mustCall = function ( fn , expected ) {
400
- if ( typeof expected !== 'number' ) expected = 1 ;
400
+ if ( expected === undefined )
401
+ expected = 1 ;
402
+ else if ( typeof expected !== 'number' )
403
+ throw new TypeError ( `Invalid expected value: ${ expected } ` ) ;
401
404
402
405
const context = {
403
406
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