11import { AllArguments } from "./Arguments" ;
22
33export type NoArgumentFunctionSubstitute < TReturnType > =
4- ( ( ) => ( TReturnType & NoArgumentMockObjectMixin < TReturnType > ) )
4+ TReturnType extends Promise < infer U > ?
5+ ( ( ) => ( TReturnType & NoArgumentMockObjectPromise < TReturnType > ) ) :
6+ ( ( ) => ( TReturnType & NoArgumentMockObjectMixin < TReturnType > ) )
57
68export type FunctionSubstitute < TArguments extends any [ ] , TReturnType > =
7- ( ( ...args : TArguments ) => ( TReturnType & MockObjectMixin < TArguments , TReturnType > ) ) &
8- ( ( allArguments : AllArguments ) => ( TReturnType & MockObjectMixin < TArguments , 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 > ) )
914
1015export type PropertySubstitute < TReturnType > = ( TReturnType & Partial < NoArgumentMockObjectMixin < TReturnType > > ) ;
1116
17+ type Unpacked < T > =
18+ T extends Promise < infer U > ? U :
19+ T ;
20+
1221type BaseMockObjectMixin < TReturnType > = {
1322 returns : ( ...args : TReturnType [ ] ) => void ;
1423 throws : ( exception : any ) => void ;
@@ -22,6 +31,16 @@ type MockObjectMixin<TArguments extends any[], TReturnType> = BaseMockObjectMixi
2231 mimicks : ( func : ( ...args : TArguments ) => TReturnType ) => void ;
2332}
2433
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+
2544export type ObjectSubstitute < T extends Object , K extends Object = T > = ObjectSubstituteTransformation < T > & {
2645 received ( amount ?: number ) : TerminatingObject < K > ;
2746 didNotReceive ( ) : TerminatingObject < K > ;
0 commit comments