|
1 |
| -type MockableFunction = (...args: any[]) => any |
2 |
| -type MethodKeysOf<T> = { [K in keyof T]: T[K] extends MockableFunction ? K : never }[keyof T] |
3 |
| -type PropertyKeysOf<T> = { [K in keyof T]: T[K] extends MockableFunction ? never : K }[keyof T] |
4 |
| -type ArgumentsOf<T> = T extends (...args: infer A) => any ? A : never |
5 |
| -type ConstructorArgumentsOf<T> = T extends new (...args: infer A) => any ? A : never |
| 1 | +export type MockableFunction = (...args: any[]) => any |
| 2 | +export type MethodKeysOf<T> = { [K in keyof T]: T[K] extends MockableFunction ? K : never }[keyof T] |
| 3 | +export type PropertyKeysOf<T> = { [K in keyof T]: T[K] extends MockableFunction ? never : K }[keyof T] |
| 4 | +export type ArgumentsOf<T> = T extends (...args: infer A) => any ? A : never |
| 5 | +export type ConstructorArgumentsOf<T> = T extends new (...args: infer A) => any ? A : never |
6 | 6 |
|
7 |
| -interface MockWithArgs<T extends MockableFunction> extends jest.MockInstance<ReturnType<T>, ArgumentsOf<T>> { |
| 7 | +export interface MockWithArgs<T extends MockableFunction> extends jest.MockInstance<ReturnType<T>, ArgumentsOf<T>> { |
8 | 8 | new (...args: ConstructorArgumentsOf<T>): T
|
9 | 9 | (...args: ArgumentsOf<T>): ReturnType<T>
|
10 | 10 | }
|
11 | 11 |
|
12 |
| -type MaybeMockedConstructor<T> = T extends new (...args: any[]) => infer R |
| 12 | +export type MaybeMockedConstructor<T> = T extends new (...args: any[]) => infer R |
13 | 13 | ? jest.MockInstance<R, ConstructorArgumentsOf<T>>
|
14 | 14 | : T
|
15 |
| -type MockedFunction<T extends MockableFunction> = MockWithArgs<T> & { [K in keyof T]: T[K] } |
16 |
| -type MockedFunctionDeep<T extends MockableFunction> = MockWithArgs<T> & MockedObjectDeep<T> |
17 |
| -type MockedObject<T> = MaybeMockedConstructor<T> & |
| 15 | +export type MockedFunction<T extends MockableFunction> = MockWithArgs<T> & { [K in keyof T]: T[K] } |
| 16 | +export type MockedFunctionDeep<T extends MockableFunction> = MockWithArgs<T> & MockedObjectDeep<T> |
| 17 | +export type MockedObject<T> = MaybeMockedConstructor<T> & |
18 | 18 | { [K in MethodKeysOf<T>]: T[K] extends MockableFunction ? MockedFunction<T[K]> : T[K] } &
|
19 | 19 | { [K in PropertyKeysOf<T>]: T[K] }
|
20 |
| -type MockedObjectDeep<T> = MaybeMockedConstructor<T> & |
| 20 | +export type MockedObjectDeep<T> = MaybeMockedConstructor<T> & |
21 | 21 | { [K in MethodKeysOf<T>]: T[K] extends MockableFunction ? MockedFunctionDeep<T[K]> : T[K] } &
|
22 | 22 | { [K in PropertyKeysOf<T>]: MaybeMockedDeep<T[K]> }
|
23 | 23 |
|
|
0 commit comments