a 4.0.3 → 4.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.d.ts +90 -82
- package/package.json +1 -1
package/index.d.ts
CHANGED
|
@@ -1,38 +1,44 @@
|
|
|
1
1
|
type AnyFunction = (...args: any[]) => any;
|
|
2
2
|
type Tail<T extends any[]> = T extends [any, ...infer R] ? R : [];
|
|
3
|
+
type FunctionProps<T> = T extends (...args: any[]) => any
|
|
4
|
+
? { [K in Exclude<keyof T, keyof Function>]: Mocked<T[K]> }
|
|
5
|
+
: {};
|
|
3
6
|
type MockedFunction<T extends AnyFunction> = MockFunction<
|
|
4
7
|
Parameters<T>,
|
|
5
8
|
ReturnType<T>
|
|
6
9
|
> &
|
|
7
|
-
T
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
10
|
+
T &
|
|
11
|
+
FunctionProps<T>;
|
|
12
|
+
|
|
13
|
+
interface RepeatControl {
|
|
14
|
+
repeat(times: number): RepeatControl;
|
|
15
|
+
repeatAny(): RepeatControl;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
interface ExpectationTerminal<R, TArgs extends any[]> {
|
|
19
|
+
return(value?: R): RepeatControl;
|
|
20
|
+
whenCalled(callback: (...args: TArgs) => void): ExpectationTerminal<R, TArgs>;
|
|
21
|
+
repeat(times: number): RepeatControl;
|
|
22
|
+
repeatAny(): RepeatControl;
|
|
23
|
+
throw(error: unknown): ExpectationTerminal<R, TArgs>;
|
|
24
|
+
resolve(value: any): RepeatControl;
|
|
25
|
+
reject(value: any): RepeatControl;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
interface ExpectationChain<TArgs extends any[], R>
|
|
29
|
+
extends ExpectationTerminal<R, TArgs> {
|
|
30
|
+
expect(arg: TArgs[0]): ExpectationChain<Tail<TArgs>, R>;
|
|
31
|
+
expectAnything(): ExpectationChain<Tail<TArgs>, R>;
|
|
32
|
+
ignore(): ExpectationChain<Tail<TArgs>, R>;
|
|
33
|
+
expectArray(
|
|
34
|
+
value: TArgs[0] extends any[] ? TArgs[0] : any[]
|
|
35
|
+
): ExpectationChain<Tail<TArgs>, R>;
|
|
36
|
+
}
|
|
37
|
+
|
|
34
38
|
interface MockFunction<TArgs extends any[], R> {
|
|
35
39
|
(...args: TArgs): R;
|
|
40
|
+
// Allow any-args calls in addition to the original signature.
|
|
41
|
+
(...args: any[]): any;
|
|
36
42
|
expect(): ExpectationTerminal<R, TArgs>;
|
|
37
43
|
expect(...args: TArgs): ExpectationTerminal<R, TArgs>;
|
|
38
44
|
expect(arg: TArgs[0]): ExpectationChain<Tail<TArgs>, R>;
|
|
@@ -41,61 +47,63 @@ interface MockFunction<TArgs extends any[], R> {
|
|
|
41
47
|
expectArray(
|
|
42
48
|
value: TArgs[0] extends any[] ? TArgs[0] : any[]
|
|
43
49
|
): ExpectationChain<Tail<TArgs>, R>;
|
|
50
|
+
// Allow any-args expectations in addition to typed expectations.
|
|
51
|
+
expect(...args: any[]): ExpectationTerminal<any, any[]>;
|
|
44
52
|
verify(): true;
|
|
45
53
|
reset(): void;
|
|
46
54
|
}
|
|
47
|
-
|
|
48
|
-
type Mocked<T> = T extends AnyFunction
|
|
49
|
-
? MockedFunction<T>
|
|
50
|
-
: T extends object
|
|
51
|
-
? { [K in keyof T]: Mocked<T[K]> } & { verify: () => true }
|
|
52
|
-
: T;
|
|
53
|
-
|
|
54
|
-
interface RequireExpectation {
|
|
55
|
-
return(value: any): RequireExpectation;
|
|
56
|
-
repeat(times: number): RequireExpectation;
|
|
57
|
-
repeatAny(): RequireExpectation;
|
|
58
|
-
whenCalled(callback: (...args: any[]) => void): RequireExpectation;
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
interface ThenableMock<T = any> {
|
|
62
|
-
(valueToResolveWith?: T | null, errorToFailWith?: any): ThenableMock<T>;
|
|
63
|
-
then<U = T>(
|
|
64
|
-
success?: (value: T) => U | ThenableMock<U> | PromiseLike<U>,
|
|
65
|
-
fail?: (error: any) => U | ThenableMock<U> | PromiseLike<U>
|
|
66
|
-
): ThenableMock<U>;
|
|
67
|
-
resolve(value?: T): ThenableMock<T>;
|
|
68
|
-
reject(error: any): ThenableMock<never>;
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
declare function mock<TArgs extends any[] = any[], R = any>(): MockFunction<
|
|
72
|
-
TArgs,
|
|
73
|
-
R
|
|
74
|
-
>;
|
|
75
|
-
declare function mock<T extends AnyFunction>(
|
|
76
|
-
original: T
|
|
77
|
-
): MockedFunction<T>;
|
|
78
|
-
declare function mock<T extends object>(subject: T): Mocked<T>;
|
|
79
|
-
|
|
80
|
-
declare function expectRequire(moduleName: string): RequireExpectation;
|
|
81
|
-
declare namespace expectRequire {
|
|
82
|
-
function reset(): void;
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
declare function requireMock<TArgs extends any[] = any[], R = any>(
|
|
86
|
-
moduleName: string
|
|
87
|
-
): MockFunction<TArgs, R>;
|
|
88
|
-
declare namespace requireMock {
|
|
89
|
-
function reset(): void;
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
declare function promise<T = any>(): ThenableMock<T>;
|
|
93
|
-
|
|
94
|
-
declare const aMock: {
|
|
95
|
-
mock: typeof mock;
|
|
96
|
-
expectRequire: typeof expectRequire;
|
|
97
|
-
requireMock: typeof requireMock;
|
|
98
|
-
promise: typeof promise;
|
|
99
|
-
};
|
|
100
|
-
|
|
101
|
-
export = aMock;
|
|
55
|
+
|
|
56
|
+
type Mocked<T> = T extends AnyFunction
|
|
57
|
+
? MockedFunction<T>
|
|
58
|
+
: T extends object
|
|
59
|
+
? { [K in keyof T]: Mocked<T[K]> } & { verify: () => true }
|
|
60
|
+
: T;
|
|
61
|
+
|
|
62
|
+
interface RequireExpectation {
|
|
63
|
+
return(value: any): RequireExpectation;
|
|
64
|
+
repeat(times: number): RequireExpectation;
|
|
65
|
+
repeatAny(): RequireExpectation;
|
|
66
|
+
whenCalled(callback: (...args: any[]) => void): RequireExpectation;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
interface ThenableMock<T = any> {
|
|
70
|
+
(valueToResolveWith?: T | null, errorToFailWith?: any): ThenableMock<T>;
|
|
71
|
+
then<U = T>(
|
|
72
|
+
success?: (value: T) => U | ThenableMock<U> | PromiseLike<U>,
|
|
73
|
+
fail?: (error: any) => U | ThenableMock<U> | PromiseLike<U>
|
|
74
|
+
): ThenableMock<U>;
|
|
75
|
+
resolve(value?: T): ThenableMock<T>;
|
|
76
|
+
reject(error: any): ThenableMock<never>;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
declare function mock<TArgs extends any[] = any[], R = any>(): MockFunction<
|
|
80
|
+
TArgs,
|
|
81
|
+
R
|
|
82
|
+
>;
|
|
83
|
+
declare function mock<T extends AnyFunction>(
|
|
84
|
+
original: T
|
|
85
|
+
): MockedFunction<T>;
|
|
86
|
+
declare function mock<T extends object>(subject: T): Mocked<T>;
|
|
87
|
+
|
|
88
|
+
declare function expectRequire(moduleName: string): RequireExpectation;
|
|
89
|
+
declare namespace expectRequire {
|
|
90
|
+
function reset(): void;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
declare function requireMock<TArgs extends any[] = any[], R = any>(
|
|
94
|
+
moduleName: string
|
|
95
|
+
): MockFunction<TArgs, R>;
|
|
96
|
+
declare namespace requireMock {
|
|
97
|
+
function reset(): void;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
declare function promise<T = any>(): ThenableMock<T>;
|
|
101
|
+
|
|
102
|
+
declare const aMock: {
|
|
103
|
+
mock: typeof mock;
|
|
104
|
+
expectRequire: typeof expectRequire;
|
|
105
|
+
requireMock: typeof requireMock;
|
|
106
|
+
promise: typeof promise;
|
|
107
|
+
};
|
|
108
|
+
|
|
109
|
+
export = aMock;
|