@@ -5,9 +5,6 @@ import { Inject } from "./inject";
55const weakHandler = new WeakMap < object , MockHandler < object > > ( ) ;
66const weakMock = new WeakMap < object , Mock < object > > ( ) ;
77
8- function noop ( ) { }
9- const empty = { } ;
10-
118export type Callable = ( ...args : any [ ] ) => any ;
129
1310export type Constructable = new ( ...args : any [ ] ) => any ;
@@ -111,7 +108,7 @@ export class Mock<T extends object> {
111108 public static spy < T extends { [ P in K ] : ( ...args : any [ ] ) => any } , K extends keyof T > ( object ?: T , propertyKey ?: K ) {
112109 return object !== undefined && propertyKey !== undefined
113110 ? new Spy ( object , propertyKey )
114- : new Mock ( object || noop ) ;
111+ : new Mock ( object || function ( ) { } ) ;
115112 }
116113
117114 /**
@@ -221,7 +218,7 @@ export class Spy<T extends { [P in K]: (...args: any[]) => any }, K extends keyo
221218
222219class Recording {
223220 public static readonly noThisArg = { } ;
224- public readonly trap : string ;
221+ public readonly trap : "apply" | "construct" | "invoke" | "get" | "set" ;
225222 public readonly name : PropertyKey | undefined ;
226223 public readonly thisArg : any ;
227224 public readonly argArray : ReadonlyArray < any > ;
@@ -233,7 +230,7 @@ class Recording {
233230 private _newTargetCondition : Arg | undefined ;
234231 private _conditions : ReadonlyArray < Arg > | undefined ;
235232
236- constructor ( trap : string , name : PropertyKey | undefined , thisArg : any , argArray : ReadonlyArray < any > , newTarget : any , result : Partial < Returns < any > & Throws & Fallback > | undefined , callback : Callable | undefined ) {
233+ constructor ( trap : "apply" | "construct" | "invoke" | "get" | "set" , name : PropertyKey | undefined , thisArg : any , argArray : ReadonlyArray < any > , newTarget : any , result : Partial < Returns < any > & Throws & Fallback > | undefined , callback : Callable | undefined ) {
237234 this . trap = trap ;
238235 this . name = name ;
239236 this . thisArg = thisArg ;
@@ -450,7 +447,7 @@ class MockHandler<T extends object> implements ProxyHandler<T> {
450447 }
451448
452449 protected capture < U > ( callback : ( value : T ) => U , result : Setup < any > | undefined ) {
453- return this . captureCore ( < T > empty , new CapturingHandler < T , U > ( result ) , callback ) ;
450+ return this . captureCore ( < T > { } , new CapturingHandler < T , U > ( result ) , callback ) ;
454451 }
455452
456453 protected captureCore < T extends object , U > ( target : T , handler : CapturingHandler < T , U > , callback : ( value : T ) => U ) : Recording {
@@ -471,7 +468,7 @@ class MockHandler<T extends object> implements ProxyHandler<T> {
471468 const setups = this . setups ;
472469 this . setupMembers ( {
473470 [ name ] ( ...argArray : any [ ] ) {
474- return Recording . evaluate ( setups , "invoke" , name , this , argArray , /*newTarget*/ undefined , noop ) ;
471+ return Recording . evaluate ( setups , "invoke" , name , this , argArray , /*newTarget*/ undefined , ( ) => { } ) ;
475472 }
476473 } ) ;
477474 }
@@ -480,10 +477,10 @@ class MockHandler<T extends object> implements ProxyHandler<T> {
480477 const setups = this . setups ;
481478 this . setupMembers ( {
482479 get [ name ] ( ) {
483- return Recording . evaluate ( setups , "get" , name , this , [ ] , /*newTarget*/ undefined , noop ) ;
480+ return Recording . evaluate ( setups , "get" , name , this , [ ] , /*newTarget*/ undefined , ( ) => { } ) ;
484481 } ,
485482 set [ name ] ( value : any ) {
486- Recording . evaluate ( setups , "set" , name , this , [ value ] , /*newTarget*/ undefined , noop ) ;
483+ Recording . evaluate ( setups , "set" , name , this , [ value ] , /*newTarget*/ undefined , ( ) => { } ) ;
487484 }
488485 } ) ;
489486 }
@@ -519,7 +516,7 @@ class MockFunctionHandler<T extends Callable | Constructable> extends MockHandle
519516 }
520517
521518 protected capture < U > ( callback : ( value : T ) => U , result : Returns < any > & ThisArg | Returns < any > | Throws & ThisArg | Throws | ThisArg | undefined ) {
522- return this . captureCore ( < T > noop , new CapturingFunctionHandler < T , U > ( result ) , callback ) ;
519+ return this . captureCore ( < T > function ( ) { } , new CapturingFunctionHandler < T , U > ( result ) , callback ) ;
523520 }
524521}
525522
0 commit comments