-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstutil.d.ts
175 lines (151 loc) · 5.05 KB
/
stutil.d.ts
1
2
3
4
5
6
7
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
// Assertions
interface IAssertion
extends IEqualityAssertion,
ITruthinessAssertion,
IComparisonAssertion,
ITypeAssertion,
IPropertyAssertion,
IErrorAssertion,
ICollectionAssertion,
IStringAssertion,
ISnapshotAssertion {
toSatisfy(predicate: (value: any) => boolean): IAssertion;
}
interface IEqualityAssertion {
toEqual(expected: any): IAssertion;
toNotEqual(expected: any): IAssertion;
toStrictEqual(expected: any): IAssertion;
toStrictNotEqual(expected: any): IAssertion;
toBe(expected: any): IAssertion;
toNotBe(expected: any): IAssertion;
toDeepEqual(expected: any): IAssertion;
toObjectEqual(expected: any): IAssertion;
}
interface ITruthinessAssertion {
toBeTruthy(): IAssertion;
toBeFalsy(): IAssertion;
}
interface IComparisonAssertion {
toBeGreaterThan(expected: number): IAssertion;
toBeGreaterThanOrEqual(expected: number): IAssertion;
toBeLessThan(expected: number): IAssertion;
toBeLessThanOrEqual(expected: number): IAssertion;
}
interface ITypeAssertion {
toBeDefined(): IAssertion;
toBeUndefined(): IAssertion;
toBeNull(): IAssertion;
toBeNotNull(): IAssertion;
toBeNaN(): IAssertion;
toBeFinite(): IAssertion;
toBeTypeOf(type: any): IAssertion;
}
interface IPropertyAssertion {
toHaveProperty(property: any): IAssertion;
toHaveAllProperties(properties: any[]): IAssertion;
toHaveAnyProperties(properties: any[]): IAssertion;
toHavePropertyEqual(property: any, value: any): IAssertion;
toHaveLength(expected: number): IAssertion;
}
interface IErrorAssertion {
toThrow(error?: ErrorConstructor, ...args: any[]): IAssertion;
toNotThrow(error?: ErrorConstructor, ...args: any[]): IAssertion;
}
interface ICollectionAssertion {
toContain(expected: any): IAssertion;
toContainEqual(expected: any): IAssertion;
toIncludeAllMembers(expected: any[]): IAssertion;
toIncludeAnyMembers(expected: any[]): IAssertion;
}
interface IStringAssertion {
toMatch(expected: RegExp | string): IAssertion;
toStartWith(expected: string): IAssertion;
toEndWith(expected: string): IAssertion;
}
interface ISnapshotAssertion {
toMatchSnapshot(name?: string): IAssertion;
}
export function assertThat(actual: any): IAssertion;
// Decorators
interface IDataTable {
readonly inputs: any[];
readonly expected: any;
}
export function Case(
options?: string | { description?: string; timeout?: number },
): MethodDecorator;
export function DataSet(...dataSets: any[][]): MethodDecorator;
export function DataTable(dataTable: IDataTable[]): MethodDecorator;
export function Test(testName?: string): ClassDecorator;
export function BeforeAll(description?: string): MethodDecorator;
export function BeforeEach(description?: string): MethodDecorator;
export function AfterAll(description?: string): MethodDecorator;
export function AfterEach(description?: string): MethodDecorator;
// Mocking
type AnyFunction = (...args: any[]) => any;
type MethodNames<T> = {
[K in keyof T]: T[K] extends AnyFunction ? K : never;
}[keyof T];
type MockTypes = Mock<any> | MockModule | MockFn;
export class MockRegistry {
public static restoreAll(): void;
}
export class Mock<T> {
constructor(target: T);
public mockMethod<K extends MethodNames<T> & string>(
methodName: K,
implementation: AnyFunction,
): void;
public verifyCalled<K extends MethodNames<T> & string>(
methodName: K,
expectedCallCount: number,
): void;
public verifyCalledWith<K extends MethodNames<T> & string>(
methodName: K,
expectedArgs: any[],
): void;
public restoreMethod<K extends MethodNames<T> & string>(methodName: K): void;
public restoreAll(): void;
}
export class MockFn {
constructor(fn: AnyFunction, implementation?: AnyFunction);
public mock(implementation: AnyFunction): void;
public verifyCalled(expectedCallCount: number): void;
public verifyCalledWith(expectedArgs: any[]): void;
public restore(): void;
public getFunction(): AnyFunction;
public call(...args: any[]): any;
}
export class MockModule {
constructor(moduleName: string);
public mockMethod(methodName: string, implementation: AnyFunction): void;
public verifyCalled(methodName: string, expectedCallCount: number): void;
public verifyCalledWith(methodName: string, expectedArgs: any[]): void;
public restoreMethod(methodName: string): void;
public restoreAll(): void;
}
// Spy
class Spy {
constructor(originalFunction: AnyFunction, context?: any);
get spyFn(): (...args: any[]) => unknown;
public getCallCount(): number;
public getCallOrder(): number[];
public getCallResults(callIndex?: number): any[];
public getCallArgs(callIndex?: number): any[][];
public getThrownErrors(callIndex?: number): any[];
public wasCalled(): boolean;
public wasCalledWith(...args: any[]): boolean;
public call(...args: any[]): void;
}
export function spyOn(object: any, methodName?: string): Spy;
// Snapshot
export function shot(name: string, data: any): void;
// Config Type
export type StestConfig = {
pattern?: string;
ignore?: string[];
cacheWatcher?: boolean;
autoClearMocks?: boolean;
enableReporting?: boolean;
};
export {};