|
1 |
| -export type TestDouble = Function; |
2 | 1 |
|
3 |
| -export type DoubledObjectWithKey<Key extends string> = {}; |
| 2 | +// |
| 3 | +// types and interfaces |
| 4 | +// ---------------------------------------------------------------------------- |
4 | 5 |
|
5 | 6 | export type DoubledObject<Subject> = Subject;
|
6 | 7 |
|
7 |
| -export interface TestdoubleConfig { |
8 |
| - promiseConstructor?: any; |
9 |
| - ignoreWarnings?: boolean; |
10 |
| - suppressErrors?: boolean; |
11 |
| -} |
12 |
| -export function config(config: TestdoubleConfig): void; |
13 |
| - |
14 |
| -declare function functionDouble(name?: string): TestDouble; |
15 |
| -export { functionDouble as function }; |
16 |
| - |
17 |
| -// When passed class or constructor function |
18 |
| -export function object<T>(constructor: { new (...args: any[]): T }): DoubledObject<T>; |
19 |
| - |
20 |
| -// When passed array of props |
21 |
| -export function object<Key extends string>(props: Key[]): DoubledObjectWithKey<Key>; |
22 |
| - |
23 |
| -// When passed class or constuctor function name as string value |
24 |
| -export function object<T>(object: string): DoubledObject<T>; |
| 8 | +export type DoubledObjectWithKey<Key extends string> = {}; |
25 | 9 |
|
26 |
| -// When passed general object |
27 |
| -export function object<T>(object: T): DoubledObject<T>; |
| 10 | +export type TestDouble<Function> = Function; |
28 | 11 |
|
29 |
| -export interface Stubber { |
30 |
| - thenReturn(...args: any[]): TestDouble; |
31 |
| - thenDo(f: Function): TestDouble; |
32 |
| - thenThrow(e: Error): TestDouble; |
33 |
| - thenResolve(v: any): TestDouble; |
34 |
| - thenReject(e: Error): TestDouble; |
35 |
| - thenCallback(...args: any[]): TestDouble; |
| 12 | +interface Call { |
| 13 | + context: {}; |
| 14 | + args: any[]; |
36 | 15 | }
|
37 | 16 |
|
38 |
| -export function callback(...args: any[]): void; |
| 17 | +export interface Captor { |
| 18 | + capture(): any; |
| 19 | + value?: any; |
| 20 | + values?: any[]; |
| 21 | +} |
39 | 22 |
|
40 |
| -export function when(...args: any[]): Stubber; |
| 23 | +export interface Explanation { |
| 24 | + callCount: number; |
| 25 | + calls: Call[]; |
| 26 | + description: string; |
| 27 | +} |
41 | 28 |
|
42 | 29 | export interface Matchers {
|
43 | 30 | anything(): any;
|
44 | 31 | isA(type: Function): any;
|
45 |
| - contains(a: string|any[]|{}): any; |
| 32 | + contains(a: string | any[] | {}): any; |
46 | 33 | argThat(matcher: Function): any;
|
47 | 34 | not(v: any): any;
|
48 | 35 | captor(): Captor
|
49 | 36 | }
|
50 | 37 |
|
51 |
| -export interface Captor { |
52 |
| - capture(): any; |
53 |
| - value?: any; |
54 |
| - values?: any[]; |
55 |
| -} |
56 |
| - |
57 | 38 | export const matchers: Matchers;
|
58 | 39 |
|
59 |
| -export function replace(path: string, f?: any): any; |
60 |
| -export function replace(path: {}, property: string, f?: any): any; |
| 40 | +export interface Stubber { |
| 41 | + thenReturn<T>(...args: any[]): TestDouble<T>; |
| 42 | + thenDo<T>(f: Function): TestDouble<T>; |
| 43 | + thenThrow<T>(e: Error): TestDouble<T>; |
| 44 | + thenResolve<T>(v: any): TestDouble<T>; |
| 45 | + thenReject<T>(e: Error): TestDouble<T>; |
| 46 | + thenCallback<T>(...args: any[]): TestDouble<T>; |
| 47 | +} |
61 | 48 |
|
62 |
| -export function reset(): void; |
| 49 | +export interface TestdoubleConfig { |
| 50 | + promiseConstructor?: any; |
| 51 | + ignoreWarnings?: boolean; |
| 52 | + suppressErrors?: boolean; |
| 53 | +} |
63 | 54 |
|
64 | 55 | export interface VerificationConfig {
|
65 | 56 | ignoreExtraArgs?: boolean;
|
66 | 57 | times?: number;
|
67 | 58 | }
|
68 | 59 |
|
69 |
| -export function verify(a: any, check?: VerificationConfig): void; |
| 60 | +// |
| 61 | +// general |
| 62 | +// ---------------------------------------------------------------------------- |
70 | 63 |
|
71 |
| -interface Call { |
72 |
| - context: {}; |
73 |
| - args: any[]; |
74 |
| -} |
| 64 | +export function config(config: TestdoubleConfig): void; |
75 | 65 |
|
76 |
| -export interface Explanation { |
77 |
| - callCount: number; |
78 |
| - calls: Call[]; |
79 |
| - description: string; |
80 |
| -} |
| 66 | +export function reset(): void; |
| 67 | + |
| 68 | +export function explain<T>(f: TestDouble<T>): Explanation; |
| 69 | + |
| 70 | + |
| 71 | +// |
| 72 | +// fake: constructors |
| 73 | +// ---------------------------------------------------------------------------- |
| 74 | + |
| 75 | +// |
| 76 | +// fake: functions |
| 77 | +// ---------------------------------------------------------------------------- |
| 78 | + |
| 79 | +declare function functionDouble(name?: string): TestDouble<Function>; |
81 | 80 |
|
82 |
| -export function explain(f: TestDouble): Explanation; |
| 81 | +declare function functionDouble<T>(name?: T): TestDouble<T>; |
| 82 | + |
| 83 | +export { functionDouble as function }; |
| 84 | +export { functionDouble as func }; |
| 85 | + |
| 86 | +// |
| 87 | +// fake: objects |
| 88 | +// ---------------------------------------------------------------------------- |
| 89 | + |
| 90 | +export function object<T>(constructor: { new (...args: any[]): T }): DoubledObject<T>; |
| 91 | + |
| 92 | +export function object<Key extends string>(props: Key[]): DoubledObjectWithKey<Key>; |
| 93 | + |
| 94 | +export function object<T>(object: string): DoubledObject<T>; |
| 95 | + |
| 96 | +export function object<T>(object: T): DoubledObject<T>; |
| 97 | + |
| 98 | +// |
| 99 | +// stubbing |
| 100 | +// ---------------------------------------------------------------------------- |
| 101 | + |
| 102 | +export function callback(...args: any[]): void; |
| 103 | + |
| 104 | +export function replace(path: string, f?: any): any; |
| 105 | + |
| 106 | +export function replace(path: {}, property: string, f?: any): any; |
| 107 | + |
| 108 | +export function when(...args: any[]): Stubber; |
| 109 | + |
| 110 | +export function verify(a: any, check?: VerificationConfig): void; |
0 commit comments