11import { AllArguments } from "./Arguments" ;
22
3- export type NoArgumentFunctionSubstitute < TReturnType > =
4- TReturnType extends Promise < infer U > ?
5- ( ( ) => ( TReturnType & NoArgumentMockObjectPromise < TReturnType > ) ) :
6- ( ( ) => ( TReturnType & NoArgumentMockObjectMixin < TReturnType > ) )
3+ export type NoArgumentFunctionSubstitute < TReturnType > = ( ( ) => ( TReturnType & NoArgumentMockObjectMixin < TReturnType > ) )
74
85export type FunctionSubstitute < TArguments extends any [ ] , TReturnType > =
9- TReturnType extends Promise < infer U > ?
10- ( ( ...args : TArguments ) => ( TReturnType & MockObjectPromise < TArguments , TReturnType > ) ) &
11- ( ( allArguments : AllArguments ) => ( TReturnType & MockObjectPromise < TArguments , TReturnType > ) ) :
12- ( ( ...args : TArguments ) => ( TReturnType & MockObjectMixin < TArguments , TReturnType > ) ) &
13- ( ( allArguments : AllArguments ) => ( TReturnType & MockObjectMixin < TArguments , TReturnType > ) )
6+ ( ( ...args : TArguments ) => ( TReturnType & MockObjectMixin < TArguments , TReturnType > ) ) &
7+ ( ( allArguments : AllArguments ) => ( TReturnType & MockObjectMixin < TArguments , TReturnType > ) )
148
159export type PropertySubstitute < TReturnType > = ( TReturnType & Partial < NoArgumentMockObjectMixin < TReturnType > > ) ;
1610
17- type Unpacked < T > =
18- T extends Promise < infer U > ? U :
19- T ;
11+ type MockObjectPromise < TReturnType > = TReturnType extends Promise < infer U > ? {
12+ resolves : ( ...args : U [ ] ) => void ;
13+ rejects : ( exception : any ) => void ;
14+ } : { }
2015
21- type BaseMockObjectMixin < TReturnType > = {
16+ type BaseMockObjectMixin < TReturnType > = MockObjectPromise < TReturnType > & {
2217 returns : ( ...args : TReturnType [ ] ) => void ;
23- throws : ( exception : any ) => void ;
18+ throws : ( exception : any ) => never ;
2419}
2520
2621type NoArgumentMockObjectMixin < TReturnType > = BaseMockObjectMixin < TReturnType > & {
@@ -31,16 +26,6 @@ type MockObjectMixin<TArguments extends any[], TReturnType> = BaseMockObjectMixi
3126 mimicks : ( func : ( ...args : TArguments ) => TReturnType ) => void ;
3227}
3328
34- type NoArgumentMockObjectPromise < TReturnType > = NoArgumentMockObjectMixin < TReturnType > & {
35- resolves : ( ...args : Unpacked < TReturnType > [ ] ) => void ;
36- rejects : ( exception : any ) => void ;
37- }
38-
39- type MockObjectPromise < TArguments extends any [ ] , TReturnType > = MockObjectMixin < TArguments , TReturnType > & {
40- resolves : ( ...args : Unpacked < TReturnType > [ ] ) => void ;
41- rejects : ( exception : any ) => void ;
42- }
43-
4429export type ObjectSubstitute < T extends Object , K extends Object = T > = ObjectSubstituteTransformation < T > & {
4530 received ( amount ?: number ) : TerminatingObject < K > ;
4631 didNotReceive ( ) : TerminatingObject < K > ;
0 commit comments