1
1
import { AllArguments } from "./Arguments" ;
2
2
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 > ) )
7
4
8
5
export 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 > ) )
14
8
15
9
export type PropertySubstitute < TReturnType > = ( TReturnType & Partial < NoArgumentMockObjectMixin < TReturnType > > ) ;
16
10
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
+ } : { }
20
15
21
- type BaseMockObjectMixin < TReturnType > = {
16
+ type BaseMockObjectMixin < TReturnType > = MockObjectPromise < TReturnType > & {
22
17
returns : ( ...args : TReturnType [ ] ) => void ;
23
- throws : ( exception : any ) => void ;
18
+ throws : ( exception : any ) => never ;
24
19
}
25
20
26
21
type NoArgumentMockObjectMixin < TReturnType > = BaseMockObjectMixin < TReturnType > & {
@@ -31,16 +26,6 @@ type MockObjectMixin<TArguments extends any[], TReturnType> = BaseMockObjectMixi
31
26
mimicks : ( func : ( ...args : TArguments ) => TReturnType ) => void ;
32
27
}
33
28
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
-
44
29
export type ObjectSubstitute < T extends Object , K extends Object = T > = ObjectSubstituteTransformation < T > & {
45
30
received ( amount ?: number ) : TerminatingObject < K > ;
46
31
didNotReceive ( ) : TerminatingObject < K > ;
0 commit comments