@rstest/core 0.1.0 → 0.1.2
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/{LICENSE → LICENSE.md} +481 -141
- package/dist/208.js +8342 -0
- package/dist/208.js.LICENSE.txt +47 -0
- package/dist/285.js +3 -1
- package/dist/355.js +3 -1
- package/dist/{950.js → 359.js} +65 -7
- package/dist/44.js +2 -0
- package/dist/443.js +1210 -0
- package/dist/629.js +2 -0
- package/dist/64.js +3 -1
- package/dist/72.js +2 -0
- package/dist/723.js +2 -0
- package/dist/813.js +3 -1
- package/dist/{562.js → 854.js} +44 -4
- package/dist/867.js +58 -44
- package/dist/965.js +2 -0
- package/dist/cli.js +20 -19
- package/dist/node.js +2 -0
- package/dist/public.js +2 -0
- package/dist/worker.js +83 -36
- package/dist-types/node.d.ts +33 -2
- package/dist-types/public.d.ts +1359 -30
- package/dist-types/worker.d.ts +1351 -23
- package/package.json +7 -8
- package/dist/81.js +0 -1467
package/dist-types/worker.d.ts
CHANGED
|
@@ -1,20 +1,124 @@
|
|
|
1
|
-
import type { addSerializer } from '@vitest/snapshot';
|
|
2
|
-
import type { Assertion as Assertion_2 } from '@vitest/expect';
|
|
3
|
-
import type { ExpectStatic as ExpectStatic_2 } from '@vitest/expect';
|
|
4
|
-
import type { MatcherState as MatcherState_2 } from '@vitest/expect';
|
|
5
1
|
import type { RsbuildConfig } from '@rsbuild/core';
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
|
|
5
|
+
*
|
|
6
|
+
* This source code is licensed under the MIT license found in the
|
|
7
|
+
* LICENSE file in the root directory of this source tree.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
declare function addSerializer(plugin: Plugin_2): void;
|
|
12
11
|
|
|
13
12
|
declare type AfterAllListener = (ctx: SuiteContext) => MaybePromise<void>;
|
|
14
13
|
|
|
15
14
|
declare type AfterEachListener = () => MaybePromise<void>;
|
|
16
15
|
|
|
17
|
-
declare interface Assertion<T = any> extends
|
|
16
|
+
declare interface Assertion<T = any> extends VitestAssertion<Chai.Assertion, T>, JestAssertion<T>, Matchers<T> {
|
|
17
|
+
/**
|
|
18
|
+
* Ensures a value is of a specific type.
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* expect(value).toBeTypeOf('string');
|
|
22
|
+
* expect(number).toBeTypeOf('number');
|
|
23
|
+
*/
|
|
24
|
+
toBeTypeOf: (expected: "bigint" | "boolean" | "function" | "number" | "object" | "string" | "symbol" | "undefined") => void;
|
|
25
|
+
/**
|
|
26
|
+
* Asserts that a mock function was called exactly once.
|
|
27
|
+
*
|
|
28
|
+
* @example
|
|
29
|
+
* expect(mockFunc).toHaveBeenCalledOnce();
|
|
30
|
+
*/
|
|
31
|
+
toHaveBeenCalledOnce: () => void;
|
|
32
|
+
/**
|
|
33
|
+
* Ensure that a mock function is called with specific arguments and called
|
|
34
|
+
* exactly once.
|
|
35
|
+
*
|
|
36
|
+
* @example
|
|
37
|
+
* expect(mockFunc).toHaveBeenCalledExactlyOnceWith('arg1', 42);
|
|
38
|
+
*/
|
|
39
|
+
toHaveBeenCalledExactlyOnceWith: <E extends any[]>(...args: E) => void;
|
|
40
|
+
/**
|
|
41
|
+
* This assertion checks if a `Mock` was called before another `Mock`.
|
|
42
|
+
* @param mock - A mock function created by `vi.spyOn` or `vi.fn`
|
|
43
|
+
* @param failIfNoFirstInvocation - Fail if the first mock was never called
|
|
44
|
+
* @example
|
|
45
|
+
* const mock1 = vi.fn()
|
|
46
|
+
* const mock2 = vi.fn()
|
|
47
|
+
*
|
|
48
|
+
* mock1()
|
|
49
|
+
* mock2()
|
|
50
|
+
* mock1()
|
|
51
|
+
*
|
|
52
|
+
* expect(mock1).toHaveBeenCalledBefore(mock2)
|
|
53
|
+
*/
|
|
54
|
+
toHaveBeenCalledBefore: (mock: MockInstance, failIfNoFirstInvocation?: boolean) => void;
|
|
55
|
+
/**
|
|
56
|
+
* This assertion checks if a `Mock` was called after another `Mock`.
|
|
57
|
+
* @param mock - A mock function created by `vi.spyOn` or `vi.fn`
|
|
58
|
+
* @param failIfNoFirstInvocation - Fail if the first mock was never called
|
|
59
|
+
* @example
|
|
60
|
+
* const mock1 = vi.fn()
|
|
61
|
+
* const mock2 = vi.fn()
|
|
62
|
+
*
|
|
63
|
+
* mock2()
|
|
64
|
+
* mock1()
|
|
65
|
+
* mock2()
|
|
66
|
+
*
|
|
67
|
+
* expect(mock1).toHaveBeenCalledAfter(mock2)
|
|
68
|
+
*/
|
|
69
|
+
toHaveBeenCalledAfter: (mock: MockInstance, failIfNoFirstInvocation?: boolean) => void;
|
|
70
|
+
/**
|
|
71
|
+
* Checks that a promise resolves successfully at least once.
|
|
72
|
+
*
|
|
73
|
+
* @example
|
|
74
|
+
* await expect(promise).toHaveResolved();
|
|
75
|
+
*/
|
|
76
|
+
toHaveResolved: () => void;
|
|
77
|
+
/**
|
|
78
|
+
* Checks that a promise resolves to a specific value.
|
|
79
|
+
*
|
|
80
|
+
* @example
|
|
81
|
+
* await expect(promise).toHaveResolvedWith('success');
|
|
82
|
+
*/
|
|
83
|
+
toHaveResolvedWith: <E>(value: E) => void;
|
|
84
|
+
/**
|
|
85
|
+
* Ensures a promise resolves a specific number of times.
|
|
86
|
+
*
|
|
87
|
+
* @example
|
|
88
|
+
* expect(mockAsyncFunc).toHaveResolvedTimes(3);
|
|
89
|
+
*/
|
|
90
|
+
toHaveResolvedTimes: (times: number) => void;
|
|
91
|
+
/**
|
|
92
|
+
* Asserts that the last resolved value of a promise matches an expected value.
|
|
93
|
+
*
|
|
94
|
+
* @example
|
|
95
|
+
* await expect(mockAsyncFunc).toHaveLastResolvedWith('finalResult');
|
|
96
|
+
*/
|
|
97
|
+
toHaveLastResolvedWith: <E>(value: E) => void;
|
|
98
|
+
/**
|
|
99
|
+
* Ensures a specific value was returned by a promise on the nth resolution.
|
|
100
|
+
*
|
|
101
|
+
* @example
|
|
102
|
+
* await expect(mockAsyncFunc).toHaveNthResolvedWith(2, 'secondResult');
|
|
103
|
+
*/
|
|
104
|
+
toHaveNthResolvedWith: <E>(nthCall: number, value: E) => void;
|
|
105
|
+
/**
|
|
106
|
+
* Verifies that a promise resolves.
|
|
107
|
+
*
|
|
108
|
+
* @example
|
|
109
|
+
* await expect(someAsyncFunc).resolves.toBe(42);
|
|
110
|
+
*/
|
|
111
|
+
resolves: PromisifyAssertion<T>;
|
|
112
|
+
/**
|
|
113
|
+
* Verifies that a promise rejects.
|
|
114
|
+
*
|
|
115
|
+
* @example
|
|
116
|
+
* await expect(someAsyncFunc).rejects.toThrow('error');
|
|
117
|
+
*/
|
|
118
|
+
rejects: PromisifyAssertion<T>;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
declare interface Assertion_2<T = any> extends Assertion<T> {
|
|
18
122
|
matchSnapshot: SnapshotMatcher<T>;
|
|
19
123
|
toMatchSnapshot: SnapshotMatcher<T>;
|
|
20
124
|
toMatchInlineSnapshot: InlineSnapshotMatcher<T>;
|
|
@@ -56,16 +160,84 @@ declare interface Assertion<T = any> extends Assertion_2<T> {
|
|
|
56
160
|
* @example
|
|
57
161
|
* await expect(someAsyncFunc).resolves.toBe(42);
|
|
58
162
|
*/
|
|
59
|
-
resolves:
|
|
163
|
+
resolves: PromisifyAssertion_2<T>;
|
|
60
164
|
/**
|
|
61
165
|
* Verifies that a promise rejects.
|
|
62
166
|
*
|
|
63
167
|
* @example
|
|
64
168
|
* await expect(someAsyncFunc).rejects.toThrow('error');
|
|
65
169
|
*/
|
|
66
|
-
rejects:
|
|
170
|
+
rejects: PromisifyAssertion_2<T>;
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
declare abstract class AsymmetricMatcher<
|
|
174
|
+
T,
|
|
175
|
+
State extends MatcherState = MatcherState
|
|
176
|
+
> implements AsymmetricMatcherInterface {
|
|
177
|
+
protected sample: T;
|
|
178
|
+
protected inverse: boolean;
|
|
179
|
+
// should have "jest" to be compatible with its ecosystem
|
|
180
|
+
$$typeof: symbol;
|
|
181
|
+
constructor(sample: T, inverse?: boolean);
|
|
182
|
+
protected getMatcherContext(expect?: Chai.ExpectStatic): State;
|
|
183
|
+
abstract asymmetricMatch(other: unknown): boolean;
|
|
184
|
+
abstract toString(): string;
|
|
185
|
+
getExpectedType?(): string;
|
|
186
|
+
toAsymmetricMatcher?(): string;
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
declare interface AsymmetricMatcherInterface {
|
|
190
|
+
asymmetricMatch: (other: unknown) => boolean;
|
|
191
|
+
toString: () => string;
|
|
192
|
+
getExpectedType?: () => string;
|
|
193
|
+
toAsymmetricMatcher?: () => string;
|
|
67
194
|
}
|
|
68
195
|
|
|
196
|
+
declare interface AsymmetricMatchersContaining extends CustomMatcher {
|
|
197
|
+
/**
|
|
198
|
+
* Matches if the received string contains the expected substring.
|
|
199
|
+
*
|
|
200
|
+
* @example
|
|
201
|
+
* expect('I have an apple').toEqual(expect.stringContaining('apple'));
|
|
202
|
+
* expect({ a: 'test string' }).toEqual({ a: expect.stringContaining('test') });
|
|
203
|
+
*/
|
|
204
|
+
stringContaining: (expected: string) => any;
|
|
205
|
+
/**
|
|
206
|
+
* Matches if the received object contains all properties of the expected object.
|
|
207
|
+
*
|
|
208
|
+
* @example
|
|
209
|
+
* expect({ a: '1', b: 2 }).toEqual(expect.objectContaining({ a: '1' }))
|
|
210
|
+
*/
|
|
211
|
+
objectContaining: <T = any>(expected: DeeplyAllowMatchers<T>) => any;
|
|
212
|
+
/**
|
|
213
|
+
* Matches if the received array contains all elements in the expected array.
|
|
214
|
+
*
|
|
215
|
+
* @example
|
|
216
|
+
* expect(['a', 'b', 'c']).toEqual(expect.arrayContaining(['b', 'a']));
|
|
217
|
+
*/
|
|
218
|
+
arrayContaining: <T = unknown>(expected: Array<DeeplyAllowMatchers<T>>) => any;
|
|
219
|
+
/**
|
|
220
|
+
* Matches if the received string or regex matches the expected pattern.
|
|
221
|
+
*
|
|
222
|
+
* @example
|
|
223
|
+
* expect('hello world').toEqual(expect.stringMatching(/^hello/));
|
|
224
|
+
* expect('hello world').toEqual(expect.stringMatching('hello'));
|
|
225
|
+
*/
|
|
226
|
+
stringMatching: (expected: string | RegExp) => any;
|
|
227
|
+
/**
|
|
228
|
+
* Matches if the received number is within a certain precision of the expected number.
|
|
229
|
+
*
|
|
230
|
+
* @param precision - Optional decimal precision for comparison. Default is 2.
|
|
231
|
+
*
|
|
232
|
+
* @example
|
|
233
|
+
* expect(10.45).toEqual(expect.closeTo(10.5, 1));
|
|
234
|
+
* expect(5.11).toEqual(expect.closeTo(5.12)); // with default precision
|
|
235
|
+
*/
|
|
236
|
+
closeTo: (expected: number, precision?: number) => any;
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
declare type AsyncExpectationResult = Promise<SyncExpectationResult>;
|
|
240
|
+
|
|
69
241
|
declare type BeforeAllListener = (ctx: SuiteContext) => MaybePromise<void | AfterAllListener>;
|
|
70
242
|
|
|
71
243
|
declare type BeforeEachListener = () => MaybePromise<void | AfterEachListener>;
|
|
@@ -76,12 +248,118 @@ declare type BuiltinReporterOptions = {
|
|
|
76
248
|
default: DefaultReporterOptions;
|
|
77
249
|
};
|
|
78
250
|
|
|
251
|
+
/**
|
|
252
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
253
|
+
*
|
|
254
|
+
* This source code is licensed under the MIT license found in the
|
|
255
|
+
* LICENSE file in the root directory of this source tree.
|
|
256
|
+
*/
|
|
257
|
+
declare interface Colors {
|
|
258
|
+
comment: {
|
|
259
|
+
close: string
|
|
260
|
+
open: string
|
|
261
|
+
};
|
|
262
|
+
content: {
|
|
263
|
+
close: string
|
|
264
|
+
open: string
|
|
265
|
+
};
|
|
266
|
+
prop: {
|
|
267
|
+
close: string
|
|
268
|
+
open: string
|
|
269
|
+
};
|
|
270
|
+
tag: {
|
|
271
|
+
close: string
|
|
272
|
+
open: string
|
|
273
|
+
};
|
|
274
|
+
value: {
|
|
275
|
+
close: string
|
|
276
|
+
open: string
|
|
277
|
+
};
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
declare type CompareKeys = ((a: string, b: string) => number) | null | undefined;
|
|
281
|
+
|
|
282
|
+
declare interface Config {
|
|
283
|
+
callToJSON: boolean;
|
|
284
|
+
compareKeys: CompareKeys;
|
|
285
|
+
colors: Colors;
|
|
286
|
+
escapeRegex: boolean;
|
|
287
|
+
escapeString: boolean;
|
|
288
|
+
indent: string;
|
|
289
|
+
maxDepth: number;
|
|
290
|
+
maxWidth: number;
|
|
291
|
+
min: boolean;
|
|
292
|
+
plugins: Plugins;
|
|
293
|
+
printBasicPrototype: boolean;
|
|
294
|
+
printFunctionName: boolean;
|
|
295
|
+
spacingInner: string;
|
|
296
|
+
spacingOuter: string;
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
declare interface Constructable {
|
|
300
|
+
new (...args: any[]): any;
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
declare class CounterMap<K> extends DefaultMap<K, number> {
|
|
304
|
+
constructor();
|
|
305
|
+
// compat for jest-image-snapshot https://github.com/vitest-dev/vitest/issues/7322
|
|
306
|
+
// `valueOf` and `Snapshot.added` setter allows
|
|
307
|
+
// snapshotState.added = snapshotState.added + 1
|
|
308
|
+
// to function as
|
|
309
|
+
// snapshotState.added.total_ = snapshotState.added.total() + 1
|
|
310
|
+
_total: number | undefined;
|
|
311
|
+
valueOf(): number;
|
|
312
|
+
increment(key: K): void;
|
|
313
|
+
total(): number;
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
declare interface CustomMatcher {
|
|
317
|
+
/**
|
|
318
|
+
* Checks that a value satisfies a custom matcher function.
|
|
319
|
+
*
|
|
320
|
+
* @param matcher - A function returning a boolean based on the custom condition
|
|
321
|
+
* @param message - Optional custom error message on failure
|
|
322
|
+
*
|
|
323
|
+
* @example
|
|
324
|
+
* expect(age).toSatisfy(val => val >= 18, 'Age must be at least 18');
|
|
325
|
+
* expect(age).toEqual(expect.toSatisfy(val => val >= 18, 'Age must be at least 18'));
|
|
326
|
+
*/
|
|
327
|
+
toSatisfy: (matcher: (value: any) => boolean, message?: string) => any;
|
|
328
|
+
/**
|
|
329
|
+
* Matches if the received value is one of the values in the expected array.
|
|
330
|
+
*
|
|
331
|
+
* @example
|
|
332
|
+
* expect(1).toBeOneOf([1, 2, 3])
|
|
333
|
+
* expect('foo').toBeOneOf([expect.any(String)])
|
|
334
|
+
* expect({ a: 1 }).toEqual({ a: expect.toBeOneOf(['1', '2', '3']) })
|
|
335
|
+
*/
|
|
336
|
+
toBeOneOf: <T>(sample: Array<T>) => any;
|
|
337
|
+
}
|
|
338
|
+
|
|
79
339
|
declare interface DecodedSourceMap extends SourceMapV3 {
|
|
80
340
|
mappings: SourceMapSegment[][];
|
|
81
341
|
}
|
|
82
342
|
|
|
83
343
|
declare type DecodedSourceMapXInput = DecodedSourceMap & XInput;
|
|
84
344
|
|
|
345
|
+
declare type DeeplyAllowMatchers<T> = T extends Array<infer Element> ? WithAsymmetricMatcher<T> | DeeplyAllowMatchers<Element>[] : T extends object ? WithAsymmetricMatcher<T> | { [K in keyof T] : DeeplyAllowMatchers<T[K]> } : WithAsymmetricMatcher<T>;
|
|
346
|
+
|
|
347
|
+
/**
|
|
348
|
+
* Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
|
|
349
|
+
*
|
|
350
|
+
* This source code is licensed under the MIT license found in the
|
|
351
|
+
* LICENSE file in the root directory of this source tree.
|
|
352
|
+
*/
|
|
353
|
+
|
|
354
|
+
declare class DefaultMap<
|
|
355
|
+
K,
|
|
356
|
+
V
|
|
357
|
+
> extends Map<K, V> {
|
|
358
|
+
private defaultFn;
|
|
359
|
+
constructor(defaultFn: (key: K) => V, entries?: Iterable<readonly [K, V]>);
|
|
360
|
+
get(key: K): V;
|
|
361
|
+
}
|
|
362
|
+
|
|
85
363
|
declare class DefaultReporter implements Reporter {
|
|
86
364
|
protected rootPath: string;
|
|
87
365
|
protected config: NormalizedConfig;
|
|
@@ -114,6 +392,49 @@ declare type DefaultReporterOptions = {
|
|
|
114
392
|
summary?: boolean;
|
|
115
393
|
};
|
|
116
394
|
|
|
395
|
+
/**
|
|
396
|
+
* @param a Expected value
|
|
397
|
+
* @param b Received value
|
|
398
|
+
* @param options Diff options
|
|
399
|
+
* @returns {string | null} a string diff
|
|
400
|
+
*/
|
|
401
|
+
declare function diff(a: any, b: any, options?: DiffOptions): string | undefined;
|
|
402
|
+
|
|
403
|
+
declare interface DiffOptions {
|
|
404
|
+
aAnnotation?: string;
|
|
405
|
+
aColor?: DiffOptionsColor;
|
|
406
|
+
aIndicator?: string;
|
|
407
|
+
bAnnotation?: string;
|
|
408
|
+
bColor?: DiffOptionsColor;
|
|
409
|
+
bIndicator?: string;
|
|
410
|
+
changeColor?: DiffOptionsColor;
|
|
411
|
+
changeLineTrailingSpaceColor?: DiffOptionsColor;
|
|
412
|
+
commonColor?: DiffOptionsColor;
|
|
413
|
+
commonIndicator?: string;
|
|
414
|
+
commonLineTrailingSpaceColor?: DiffOptionsColor;
|
|
415
|
+
contextLines?: number;
|
|
416
|
+
emptyFirstOrLastLinePlaceholder?: string;
|
|
417
|
+
expand?: boolean;
|
|
418
|
+
includeChangeCounts?: boolean;
|
|
419
|
+
omitAnnotationLines?: boolean;
|
|
420
|
+
patchColor?: DiffOptionsColor;
|
|
421
|
+
printBasicPrototype?: boolean;
|
|
422
|
+
maxDepth?: number;
|
|
423
|
+
compareKeys?: CompareKeys;
|
|
424
|
+
truncateThreshold?: number;
|
|
425
|
+
truncateAnnotation?: string;
|
|
426
|
+
truncateAnnotationColor?: DiffOptionsColor;
|
|
427
|
+
}
|
|
428
|
+
|
|
429
|
+
/**
|
|
430
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
431
|
+
*
|
|
432
|
+
* This source code is licensed under the MIT license found in the
|
|
433
|
+
* LICENSE file in the root directory of this source tree.
|
|
434
|
+
*/
|
|
435
|
+
|
|
436
|
+
declare type DiffOptionsColor = (arg: string) => string;
|
|
437
|
+
|
|
117
438
|
/** The test file output path */
|
|
118
439
|
declare type DistPath = string;
|
|
119
440
|
|
|
@@ -135,6 +456,8 @@ declare type EntryInfo = {
|
|
|
135
456
|
files?: string[];
|
|
136
457
|
};
|
|
137
458
|
|
|
459
|
+
declare type ExpectationResult = SyncExpectationResult | AsyncExpectationResult;
|
|
460
|
+
|
|
138
461
|
declare interface ExpectPollOptions {
|
|
139
462
|
/**
|
|
140
463
|
* @default 50
|
|
@@ -148,16 +471,26 @@ declare interface ExpectPollOptions {
|
|
|
148
471
|
}
|
|
149
472
|
|
|
150
473
|
declare interface ExpectStatic extends ExpectStatic_2 {
|
|
151
|
-
<T>(actual: T, message?: string):
|
|
474
|
+
<T>(actual: T, message?: string): Assertion_2<T>;
|
|
152
475
|
unreachable: (message?: string) => never;
|
|
153
|
-
soft: <T>(actual: T, message?: string) =>
|
|
154
|
-
poll: <T>(actual: () => T, options?: ExpectPollOptions) => Omit<
|
|
476
|
+
soft: <T>(actual: T, message?: string) => Assertion_2<T>;
|
|
477
|
+
poll: <T>(actual: () => T, options?: ExpectPollOptions) => Omit<PromisifyAssertion_2<Awaited<T>>, 'rejects' | 'resolves' | 'toThrow' | 'toThrowError' | 'throw' | 'throws' | 'matchSnapshot' | 'toMatchSnapshot' | 'toMatchInlineSnapshot' | 'toThrowErrorMatchingSnapshot' | 'toThrowErrorMatchingInlineSnapshot'>;
|
|
155
478
|
addEqualityTesters: (testers: Array<Tester>) => void;
|
|
156
479
|
assertions: (expected: number) => void;
|
|
157
480
|
hasAssertions: () => void;
|
|
158
481
|
addSnapshotSerializer: typeof addSerializer;
|
|
159
|
-
getState: () =>
|
|
160
|
-
setState: (state: Partial<
|
|
482
|
+
getState: () => MatcherState_2;
|
|
483
|
+
setState: (state: Partial<MatcherState_2>) => void;
|
|
484
|
+
}
|
|
485
|
+
|
|
486
|
+
declare interface ExpectStatic_2 extends Chai.ExpectStatic, Matchers, AsymmetricMatchersContaining {
|
|
487
|
+
<T>(actual: T, message?: string): Assertion<T>;
|
|
488
|
+
extend: (expects: MatchersObject) => void;
|
|
489
|
+
anything: () => any;
|
|
490
|
+
any: (constructor: unknown) => any;
|
|
491
|
+
getState: () => MatcherState;
|
|
492
|
+
setState: (state: Partial<MatcherState>) => void;
|
|
493
|
+
not: AsymmetricMatchersContaining;
|
|
161
494
|
}
|
|
162
495
|
|
|
163
496
|
declare type FixtureFn<T, K extends keyof T, ExtraContext> = (context: Omit<T, K> & ExtraContext, use: Use<T[K]>) => Promise<void>;
|
|
@@ -177,8 +510,28 @@ declare type FormattedError = {
|
|
|
177
510
|
diff?: string;
|
|
178
511
|
};
|
|
179
512
|
|
|
513
|
+
declare interface Formatter {
|
|
514
|
+
(input?: unknown): string;
|
|
515
|
+
open: string;
|
|
516
|
+
close: string;
|
|
517
|
+
}
|
|
518
|
+
|
|
180
519
|
declare type GeneratedColumn = number;
|
|
181
520
|
|
|
521
|
+
declare function getMatcherUtils(): {
|
|
522
|
+
EXPECTED_COLOR: Formatter
|
|
523
|
+
RECEIVED_COLOR: Formatter
|
|
524
|
+
INVERTED_COLOR: Formatter
|
|
525
|
+
BOLD_WEIGHT: Formatter
|
|
526
|
+
DIM_COLOR: Formatter
|
|
527
|
+
diff: typeof diff
|
|
528
|
+
matcherHint: typeof matcherHint
|
|
529
|
+
printReceived: typeof printReceived
|
|
530
|
+
printExpected: typeof printExpected
|
|
531
|
+
printDiffOrStringify: typeof printDiffOrStringify
|
|
532
|
+
printWithType: typeof printWithType
|
|
533
|
+
};
|
|
534
|
+
|
|
182
535
|
declare type GetSourcemap = (sourcePath: string) => SourceMapInput | null;
|
|
183
536
|
|
|
184
537
|
declare class GithubActionsReporter {
|
|
@@ -199,6 +552,8 @@ declare class GithubActionsReporter {
|
|
|
199
552
|
}): Promise<void>;
|
|
200
553
|
}
|
|
201
554
|
|
|
555
|
+
declare type Indent = (arg0: string) => string;
|
|
556
|
+
|
|
202
557
|
declare interface InlineSnapshotMatcher<T> {
|
|
203
558
|
<U extends {
|
|
204
559
|
[P in keyof T]: any;
|
|
@@ -206,15 +561,751 @@ declare interface InlineSnapshotMatcher<T> {
|
|
|
206
561
|
(message?: string): void;
|
|
207
562
|
}
|
|
208
563
|
|
|
209
|
-
declare interface
|
|
564
|
+
declare interface JestAssertion<T = any> extends jest.Matchers<void, T>, CustomMatcher {
|
|
565
|
+
/**
|
|
566
|
+
* Used when you want to check that two objects have the same value.
|
|
567
|
+
* This matcher recursively checks the equality of all fields, rather than checking for object identity.
|
|
568
|
+
*
|
|
569
|
+
* @example
|
|
570
|
+
* expect(user).toEqual({ name: 'Alice', age: 30 });
|
|
571
|
+
*/
|
|
572
|
+
toEqual: <E>(expected: E) => void;
|
|
573
|
+
/**
|
|
574
|
+
* Use to test that objects have the same types as well as structure.
|
|
575
|
+
*
|
|
576
|
+
* @example
|
|
577
|
+
* expect(user).toStrictEqual({ name: 'Alice', age: 30 });
|
|
578
|
+
*/
|
|
579
|
+
toStrictEqual: <E>(expected: E) => void;
|
|
580
|
+
/**
|
|
581
|
+
* Checks that a value is what you expect. It calls `Object.is` to compare values.
|
|
582
|
+
* Don't use `toBe` with floating-point numbers.
|
|
583
|
+
*
|
|
584
|
+
* @example
|
|
585
|
+
* expect(result).toBe(42);
|
|
586
|
+
* expect(status).toBe(true);
|
|
587
|
+
*/
|
|
588
|
+
toBe: <E>(expected: E) => void;
|
|
589
|
+
/**
|
|
590
|
+
* Check that a string matches a regular expression.
|
|
591
|
+
*
|
|
592
|
+
* @example
|
|
593
|
+
* expect(message).toMatch(/hello/);
|
|
594
|
+
* expect(greeting).toMatch('world');
|
|
595
|
+
*/
|
|
596
|
+
toMatch: (expected: string | RegExp) => void;
|
|
597
|
+
/**
|
|
598
|
+
* Used to check that a JavaScript object matches a subset of the properties of an object
|
|
599
|
+
*
|
|
600
|
+
* @example
|
|
601
|
+
* expect(user).toMatchObject({
|
|
602
|
+
* name: 'Alice',
|
|
603
|
+
* address: { city: 'Wonderland' }
|
|
604
|
+
* });
|
|
605
|
+
*/
|
|
606
|
+
toMatchObject: <E extends object | any[]>(expected: E) => void;
|
|
607
|
+
/**
|
|
608
|
+
* Used when you want to check that an item is in a list.
|
|
609
|
+
* For testing the items in the list, this uses `===`, a strict equality check.
|
|
610
|
+
*
|
|
611
|
+
* @example
|
|
612
|
+
* expect(items).toContain('apple');
|
|
613
|
+
* expect(numbers).toContain(5);
|
|
614
|
+
*/
|
|
615
|
+
toContain: <E>(item: E) => void;
|
|
616
|
+
/**
|
|
617
|
+
* Used when you want to check that an item is in a list.
|
|
618
|
+
* For testing the items in the list, this matcher recursively checks the
|
|
619
|
+
* equality of all fields, rather than checking for object identity.
|
|
620
|
+
*
|
|
621
|
+
* @example
|
|
622
|
+
* expect(items).toContainEqual({ name: 'apple', quantity: 1 });
|
|
623
|
+
*/
|
|
624
|
+
toContainEqual: <E>(item: E) => void;
|
|
625
|
+
/**
|
|
626
|
+
* Use when you don't care what a value is, you just want to ensure a value
|
|
627
|
+
* is true in a boolean context. In JavaScript, there are six falsy values:
|
|
628
|
+
* `false`, `0`, `''`, `null`, `undefined`, and `NaN`. Everything else is truthy.
|
|
629
|
+
*
|
|
630
|
+
* @example
|
|
631
|
+
* expect(user.isActive).toBeTruthy();
|
|
632
|
+
*/
|
|
633
|
+
toBeTruthy: () => void;
|
|
634
|
+
/**
|
|
635
|
+
* When you don't care what a value is, you just want to
|
|
636
|
+
* ensure a value is false in a boolean context.
|
|
637
|
+
*
|
|
638
|
+
* @example
|
|
639
|
+
* expect(user.isActive).toBeFalsy();
|
|
640
|
+
*/
|
|
641
|
+
toBeFalsy: () => void;
|
|
642
|
+
/**
|
|
643
|
+
* For comparing floating point numbers.
|
|
644
|
+
*
|
|
645
|
+
* @example
|
|
646
|
+
* expect(score).toBeGreaterThan(10);
|
|
647
|
+
*/
|
|
648
|
+
toBeGreaterThan: (num: number | bigint) => void;
|
|
649
|
+
/**
|
|
650
|
+
* For comparing floating point numbers.
|
|
651
|
+
*
|
|
652
|
+
* @example
|
|
653
|
+
* expect(score).toBeGreaterThanOrEqual(10);
|
|
654
|
+
*/
|
|
655
|
+
toBeGreaterThanOrEqual: (num: number | bigint) => void;
|
|
656
|
+
/**
|
|
657
|
+
* For comparing floating point numbers.
|
|
658
|
+
*
|
|
659
|
+
* @example
|
|
660
|
+
* expect(score).toBeLessThan(10);
|
|
661
|
+
*/
|
|
662
|
+
toBeLessThan: (num: number | bigint) => void;
|
|
663
|
+
/**
|
|
664
|
+
* For comparing floating point numbers.
|
|
665
|
+
*
|
|
666
|
+
* @example
|
|
667
|
+
* expect(score).toBeLessThanOrEqual(10);
|
|
668
|
+
*/
|
|
669
|
+
toBeLessThanOrEqual: (num: number | bigint) => void;
|
|
670
|
+
/**
|
|
671
|
+
* Used to check that a variable is NaN.
|
|
672
|
+
*
|
|
673
|
+
* @example
|
|
674
|
+
* expect(value).toBeNaN();
|
|
675
|
+
*/
|
|
676
|
+
toBeNaN: () => void;
|
|
677
|
+
/**
|
|
678
|
+
* Used to check that a variable is undefined.
|
|
679
|
+
*
|
|
680
|
+
* @example
|
|
681
|
+
* expect(value).toBeUndefined();
|
|
682
|
+
*/
|
|
683
|
+
toBeUndefined: () => void;
|
|
684
|
+
/**
|
|
685
|
+
* This is the same as `.toBe(null)` but the error messages are a bit nicer.
|
|
686
|
+
* So use `.toBeNull()` when you want to check that something is null.
|
|
687
|
+
*
|
|
688
|
+
* @example
|
|
689
|
+
* expect(value).toBeNull();
|
|
690
|
+
*/
|
|
691
|
+
toBeNull: () => void;
|
|
692
|
+
/**
|
|
693
|
+
* Ensure that a variable is not undefined.
|
|
694
|
+
*
|
|
695
|
+
* @example
|
|
696
|
+
* expect(value).toBeDefined();
|
|
697
|
+
*/
|
|
698
|
+
toBeDefined: () => void;
|
|
699
|
+
/**
|
|
700
|
+
* Ensure that an object is an instance of a class.
|
|
701
|
+
* This matcher uses `instanceof` underneath.
|
|
702
|
+
*
|
|
703
|
+
* @example
|
|
704
|
+
* expect(new Date()).toBeInstanceOf(Date);
|
|
705
|
+
*/
|
|
706
|
+
toBeInstanceOf: <E>(expected: E) => void;
|
|
707
|
+
/**
|
|
708
|
+
* Used to check that an object has a `.length` property
|
|
709
|
+
* and it is set to a certain numeric value.
|
|
710
|
+
*
|
|
711
|
+
* @example
|
|
712
|
+
* expect([1, 2, 3]).toHaveLength(3);
|
|
713
|
+
* expect('hello').toHaveLength(5);
|
|
714
|
+
*/
|
|
715
|
+
toHaveLength: (length: number) => void;
|
|
716
|
+
/**
|
|
717
|
+
* Use to check if a property at the specified path exists on an object.
|
|
718
|
+
* For checking deeply nested properties, you may use dot notation or an array containing
|
|
719
|
+
* the path segments for deep references.
|
|
720
|
+
*
|
|
721
|
+
* Optionally, you can provide a value to check if it matches the value present at the path
|
|
722
|
+
* on the target object. This matcher uses 'deep equality' (like `toEqual()`) and recursively checks
|
|
723
|
+
* the equality of all fields.
|
|
724
|
+
*
|
|
725
|
+
* @example
|
|
726
|
+
* expect(user).toHaveProperty('address.city', 'New York');
|
|
727
|
+
* expect(config).toHaveProperty(['settings', 'theme'], 'dark');
|
|
728
|
+
*/
|
|
729
|
+
toHaveProperty: <E>(property: string | (string | number)[], value?: E) => void;
|
|
730
|
+
/**
|
|
731
|
+
* Using exact equality with floating point numbers is a bad idea.
|
|
732
|
+
* Rounding means that intuitive things fail.
|
|
733
|
+
* The default for `precision` is 2.
|
|
734
|
+
*
|
|
735
|
+
* @example
|
|
736
|
+
* expect(price).toBeCloseTo(9.99, 2);
|
|
737
|
+
*/
|
|
738
|
+
toBeCloseTo: (number: number, numDigits?: number) => void;
|
|
739
|
+
/**
|
|
740
|
+
* Ensures that a mock function is called an exact number of times.
|
|
741
|
+
*
|
|
742
|
+
* Also under the alias `expect.toBeCalledTimes`.
|
|
743
|
+
*
|
|
744
|
+
* @example
|
|
745
|
+
* expect(mockFunc).toHaveBeenCalledTimes(2);
|
|
746
|
+
*/
|
|
747
|
+
toHaveBeenCalledTimes: (times: number) => void;
|
|
748
|
+
/**
|
|
749
|
+
* Ensures that a mock function is called an exact number of times.
|
|
750
|
+
*
|
|
751
|
+
* Alias for `expect.toHaveBeenCalledTimes`.
|
|
752
|
+
*
|
|
753
|
+
* @example
|
|
754
|
+
* expect(mockFunc).toBeCalledTimes(2);
|
|
755
|
+
*/
|
|
756
|
+
toBeCalledTimes: (times: number) => void;
|
|
757
|
+
/**
|
|
758
|
+
* Ensures that a mock function is called.
|
|
759
|
+
*
|
|
760
|
+
* Also under the alias `expect.toBeCalled`.
|
|
761
|
+
*
|
|
762
|
+
* @example
|
|
763
|
+
* expect(mockFunc).toHaveBeenCalled();
|
|
764
|
+
*/
|
|
765
|
+
toHaveBeenCalled: () => void;
|
|
766
|
+
/**
|
|
767
|
+
* Ensures that a mock function is called.
|
|
768
|
+
*
|
|
769
|
+
* Alias for `expect.toHaveBeenCalled`.
|
|
770
|
+
*
|
|
771
|
+
* @example
|
|
772
|
+
* expect(mockFunc).toBeCalled();
|
|
773
|
+
*/
|
|
774
|
+
toBeCalled: () => void;
|
|
775
|
+
/**
|
|
776
|
+
* Ensure that a mock function is called with specific arguments.
|
|
777
|
+
*
|
|
778
|
+
* Also under the alias `expect.toBeCalledWith`.
|
|
779
|
+
*
|
|
780
|
+
* @example
|
|
781
|
+
* expect(mockFunc).toHaveBeenCalledWith('arg1', 42);
|
|
782
|
+
*/
|
|
783
|
+
toHaveBeenCalledWith: <E extends any[]>(...args: E) => void;
|
|
784
|
+
/**
|
|
785
|
+
* Ensure that a mock function is called with specific arguments.
|
|
786
|
+
*
|
|
787
|
+
* Alias for `expect.toHaveBeenCalledWith`.
|
|
788
|
+
*
|
|
789
|
+
* @example
|
|
790
|
+
* expect(mockFunc).toBeCalledWith('arg1', 42);
|
|
791
|
+
*/
|
|
792
|
+
toBeCalledWith: <E extends any[]>(...args: E) => void;
|
|
793
|
+
/**
|
|
794
|
+
* Ensure that a mock function is called with specific arguments on an Nth call.
|
|
795
|
+
*
|
|
796
|
+
* Also under the alias `expect.nthCalledWith`.
|
|
797
|
+
*
|
|
798
|
+
* @example
|
|
799
|
+
* expect(mockFunc).toHaveBeenNthCalledWith(2, 'secondArg');
|
|
800
|
+
*/
|
|
801
|
+
toHaveBeenNthCalledWith: <E extends any[]>(n: number, ...args: E) => void;
|
|
802
|
+
/**
|
|
803
|
+
* Ensure that a mock function is called with specific arguments on an Nth call.
|
|
804
|
+
*
|
|
805
|
+
* Alias for `expect.toHaveBeenNthCalledWith`.
|
|
806
|
+
*
|
|
807
|
+
* @example
|
|
808
|
+
* expect(mockFunc).nthCalledWith(2, 'secondArg');
|
|
809
|
+
*/
|
|
810
|
+
nthCalledWith: <E extends any[]>(nthCall: number, ...args: E) => void;
|
|
811
|
+
/**
|
|
812
|
+
* If you have a mock function, you can use `.toHaveBeenLastCalledWith`
|
|
813
|
+
* to test what arguments it was last called with.
|
|
814
|
+
*
|
|
815
|
+
* Also under the alias `expect.lastCalledWith`.
|
|
816
|
+
*
|
|
817
|
+
* @example
|
|
818
|
+
* expect(mockFunc).toHaveBeenLastCalledWith('lastArg');
|
|
819
|
+
*/
|
|
820
|
+
toHaveBeenLastCalledWith: <E extends any[]>(...args: E) => void;
|
|
821
|
+
/**
|
|
822
|
+
* If you have a mock function, you can use `.lastCalledWith`
|
|
823
|
+
* to test what arguments it was last called with.
|
|
824
|
+
*
|
|
825
|
+
* Alias for `expect.toHaveBeenLastCalledWith`.
|
|
826
|
+
*
|
|
827
|
+
* @example
|
|
828
|
+
* expect(mockFunc).lastCalledWith('lastArg');
|
|
829
|
+
*/
|
|
830
|
+
lastCalledWith: <E extends any[]>(...args: E) => void;
|
|
831
|
+
/**
|
|
832
|
+
* Used to test that a function throws when it is called.
|
|
833
|
+
*
|
|
834
|
+
* Also under the alias `expect.toThrowError`.
|
|
835
|
+
*
|
|
836
|
+
* @example
|
|
837
|
+
* expect(() => functionWithError()).toThrow('Error message');
|
|
838
|
+
* expect(() => parseJSON('invalid')).toThrow(SyntaxError);
|
|
839
|
+
*/
|
|
840
|
+
toThrow: (expected?: string | Constructable | RegExp | Error) => void;
|
|
841
|
+
/**
|
|
842
|
+
* Used to test that a function throws when it is called.
|
|
843
|
+
*
|
|
844
|
+
* Alias for `expect.toThrow`.
|
|
845
|
+
*
|
|
846
|
+
* @example
|
|
847
|
+
* expect(() => functionWithError()).toThrowError('Error message');
|
|
848
|
+
* expect(() => parseJSON('invalid')).toThrowError(SyntaxError);
|
|
849
|
+
*/
|
|
850
|
+
toThrowError: (expected?: string | Constructable | RegExp | Error) => void;
|
|
851
|
+
/**
|
|
852
|
+
* Use to test that the mock function successfully returned (i.e., did not throw an error) at least one time
|
|
853
|
+
*
|
|
854
|
+
* Alias for `expect.toHaveReturned`.
|
|
855
|
+
*
|
|
856
|
+
* @example
|
|
857
|
+
* expect(mockFunc).toReturn();
|
|
858
|
+
*/
|
|
859
|
+
toReturn: () => void;
|
|
860
|
+
/**
|
|
861
|
+
* Use to test that the mock function successfully returned (i.e., did not throw an error) at least one time
|
|
862
|
+
*
|
|
863
|
+
* Also under the alias `expect.toReturn`.
|
|
864
|
+
*
|
|
865
|
+
* @example
|
|
866
|
+
* expect(mockFunc).toHaveReturned();
|
|
867
|
+
*/
|
|
868
|
+
toHaveReturned: () => void;
|
|
869
|
+
/**
|
|
870
|
+
* Use to ensure that a mock function returned successfully (i.e., did not throw an error) an exact number of times.
|
|
871
|
+
* Any calls to the mock function that throw an error are not counted toward the number of times the function returned.
|
|
872
|
+
*
|
|
873
|
+
* Alias for `expect.toHaveReturnedTimes`.
|
|
874
|
+
*
|
|
875
|
+
* @example
|
|
876
|
+
* expect(mockFunc).toReturnTimes(3);
|
|
877
|
+
*/
|
|
878
|
+
toReturnTimes: (times: number) => void;
|
|
879
|
+
/**
|
|
880
|
+
* Use to ensure that a mock function returned successfully (i.e., did not throw an error) an exact number of times.
|
|
881
|
+
* Any calls to the mock function that throw an error are not counted toward the number of times the function returned.
|
|
882
|
+
*
|
|
883
|
+
* Also under the alias `expect.toReturnTimes`.
|
|
884
|
+
*
|
|
885
|
+
* @example
|
|
886
|
+
* expect(mockFunc).toHaveReturnedTimes(3);
|
|
887
|
+
*/
|
|
888
|
+
toHaveReturnedTimes: (times: number) => void;
|
|
889
|
+
/**
|
|
890
|
+
* Use to ensure that a mock function returned a specific value.
|
|
891
|
+
*
|
|
892
|
+
* Alias for `expect.toHaveReturnedWith`.
|
|
893
|
+
*
|
|
894
|
+
* @example
|
|
895
|
+
* expect(mockFunc).toReturnWith('returnValue');
|
|
896
|
+
*/
|
|
897
|
+
toReturnWith: <E>(value: E) => void;
|
|
898
|
+
/**
|
|
899
|
+
* Use to ensure that a mock function returned a specific value.
|
|
900
|
+
*
|
|
901
|
+
* Also under the alias `expect.toReturnWith`.
|
|
902
|
+
*
|
|
903
|
+
* @example
|
|
904
|
+
* expect(mockFunc).toHaveReturnedWith('returnValue');
|
|
905
|
+
*/
|
|
906
|
+
toHaveReturnedWith: <E>(value: E) => void;
|
|
907
|
+
/**
|
|
908
|
+
* Use to test the specific value that a mock function last returned.
|
|
909
|
+
* If the last call to the mock function threw an error, then this matcher will fail
|
|
910
|
+
* no matter what value you provided as the expected return value.
|
|
911
|
+
*
|
|
912
|
+
* Also under the alias `expect.lastReturnedWith`.
|
|
913
|
+
*
|
|
914
|
+
* @example
|
|
915
|
+
* expect(mockFunc).toHaveLastReturnedWith('lastValue');
|
|
916
|
+
*/
|
|
917
|
+
toHaveLastReturnedWith: <E>(value: E) => void;
|
|
918
|
+
/**
|
|
919
|
+
* Use to test the specific value that a mock function last returned.
|
|
920
|
+
* If the last call to the mock function threw an error, then this matcher will fail
|
|
921
|
+
* no matter what value you provided as the expected return value.
|
|
922
|
+
*
|
|
923
|
+
* Alias for `expect.toHaveLastReturnedWith`.
|
|
924
|
+
*
|
|
925
|
+
* @example
|
|
926
|
+
* expect(mockFunc).lastReturnedWith('lastValue');
|
|
927
|
+
*/
|
|
928
|
+
lastReturnedWith: <E>(value: E) => void;
|
|
929
|
+
/**
|
|
930
|
+
* Use to test the specific value that a mock function returned for the nth call.
|
|
931
|
+
* If the nth call to the mock function threw an error, then this matcher will fail
|
|
932
|
+
* no matter what value you provided as the expected return value.
|
|
933
|
+
*
|
|
934
|
+
* Also under the alias `expect.nthReturnedWith`.
|
|
935
|
+
*
|
|
936
|
+
* @example
|
|
937
|
+
* expect(mockFunc).toHaveNthReturnedWith(2, 'nthValue');
|
|
938
|
+
*/
|
|
939
|
+
toHaveNthReturnedWith: <E>(nthCall: number, value: E) => void;
|
|
940
|
+
/**
|
|
941
|
+
* Use to test the specific value that a mock function returned for the nth call.
|
|
942
|
+
* If the nth call to the mock function threw an error, then this matcher will fail
|
|
943
|
+
* no matter what value you provided as the expected return value.
|
|
944
|
+
*
|
|
945
|
+
* Alias for `expect.toHaveNthReturnedWith`.
|
|
946
|
+
*
|
|
947
|
+
* @example
|
|
948
|
+
* expect(mockFunc).nthReturnedWith(2, 'nthValue');
|
|
949
|
+
*/
|
|
950
|
+
nthReturnedWith: <E>(nthCall: number, value: E) => void;
|
|
951
|
+
}
|
|
952
|
+
|
|
953
|
+
declare function matcherHint(matcherName: string, received?: string, expected?: string, options?: MatcherHintOptions): string;
|
|
954
|
+
|
|
955
|
+
declare interface MatcherHintOptions {
|
|
956
|
+
comment?: string;
|
|
957
|
+
expectedColor?: Formatter;
|
|
958
|
+
isDirectExpectCall?: boolean;
|
|
959
|
+
isNot?: boolean;
|
|
960
|
+
promise?: string;
|
|
961
|
+
receivedColor?: Formatter;
|
|
962
|
+
secondArgument?: string;
|
|
963
|
+
secondArgumentColor?: Formatter;
|
|
964
|
+
}
|
|
965
|
+
|
|
966
|
+
declare interface Matchers<T = any> {}
|
|
967
|
+
|
|
968
|
+
declare type MatchersObject<T extends MatcherState = MatcherState> = Record<string, RawMatcherFn<T>> & ThisType<T> & { [K in keyof Matchers<T>]? : RawMatcherFn<T, Parameters<Matchers<T>[K]>> };
|
|
969
|
+
|
|
970
|
+
declare interface MatcherState {
|
|
971
|
+
customTesters: Array<Tester>;
|
|
972
|
+
assertionCalls: number;
|
|
973
|
+
currentTestName?: string;
|
|
974
|
+
dontThrow?: () => void;
|
|
975
|
+
error?: Error;
|
|
976
|
+
equals: (a: unknown, b: unknown, customTesters?: Array<Tester>, strictCheck?: boolean) => boolean;
|
|
977
|
+
expand?: boolean;
|
|
978
|
+
expectedAssertionsNumber?: number | null;
|
|
979
|
+
expectedAssertionsNumberErrorGen?: (() => Error) | null;
|
|
980
|
+
isExpectingAssertions?: boolean;
|
|
981
|
+
isExpectingAssertionsError?: Error | null;
|
|
982
|
+
isNot: boolean;
|
|
983
|
+
// environment: VitestEnvironment
|
|
984
|
+
promise: string;
|
|
985
|
+
// snapshotState: SnapshotState
|
|
986
|
+
suppressedErrors: Array<Error>;
|
|
987
|
+
testPath?: string;
|
|
988
|
+
utils: ReturnType<typeof getMatcherUtils> & {
|
|
989
|
+
diff: typeof diff
|
|
990
|
+
stringify: typeof stringify
|
|
991
|
+
iterableEquality: Tester
|
|
992
|
+
subsetEquality: Tester
|
|
993
|
+
};
|
|
994
|
+
soft?: boolean;
|
|
995
|
+
poll?: boolean;
|
|
996
|
+
}
|
|
997
|
+
|
|
998
|
+
declare interface MatcherState_2 extends MatcherState {
|
|
210
999
|
environment: string;
|
|
211
1000
|
snapshotState: SnapshotState;
|
|
212
1001
|
}
|
|
213
1002
|
|
|
214
1003
|
declare type MaybePromise<T> = T | Promise<T>;
|
|
215
1004
|
|
|
1005
|
+
declare interface MockContext<T extends Procedure> {
|
|
1006
|
+
/**
|
|
1007
|
+
* This is an array containing all arguments for each call. One item of the array is the arguments of that call.
|
|
1008
|
+
*
|
|
1009
|
+
* @see https://vitest.dev/api/mock#mock-calls
|
|
1010
|
+
* @example
|
|
1011
|
+
* const fn = vi.fn()
|
|
1012
|
+
*
|
|
1013
|
+
* fn('arg1', 'arg2')
|
|
1014
|
+
* fn('arg3')
|
|
1015
|
+
*
|
|
1016
|
+
* fn.mock.calls === [
|
|
1017
|
+
* ['arg1', 'arg2'], // first call
|
|
1018
|
+
* ['arg3'], // second call
|
|
1019
|
+
* ]
|
|
1020
|
+
*/
|
|
1021
|
+
calls: Parameters<T>[];
|
|
1022
|
+
/**
|
|
1023
|
+
* This is an array containing all instances that were instantiated when mock was called with a `new` keyword. Note that this is an actual context (`this`) of the function, not a return value.
|
|
1024
|
+
* @see https://vitest.dev/api/mock#mock-instances
|
|
1025
|
+
*/
|
|
1026
|
+
instances: ReturnType<T>[];
|
|
1027
|
+
/**
|
|
1028
|
+
* An array of `this` values that were used during each call to the mock function.
|
|
1029
|
+
* @see https://vitest.dev/api/mock#mock-contexts
|
|
1030
|
+
*/
|
|
1031
|
+
contexts: ThisParameterType<T>[];
|
|
1032
|
+
/**
|
|
1033
|
+
* The order of mock's execution. This returns an array of numbers which are shared between all defined mocks.
|
|
1034
|
+
*
|
|
1035
|
+
* @see https://vitest.dev/api/mock#mock-invocationcallorder
|
|
1036
|
+
* @example
|
|
1037
|
+
* const fn1 = vi.fn()
|
|
1038
|
+
* const fn2 = vi.fn()
|
|
1039
|
+
*
|
|
1040
|
+
* fn1()
|
|
1041
|
+
* fn2()
|
|
1042
|
+
* fn1()
|
|
1043
|
+
*
|
|
1044
|
+
* fn1.mock.invocationCallOrder === [1, 3]
|
|
1045
|
+
* fn2.mock.invocationCallOrder === [2]
|
|
1046
|
+
*/
|
|
1047
|
+
invocationCallOrder: number[];
|
|
1048
|
+
/**
|
|
1049
|
+
* This is an array containing all values that were `returned` from the function.
|
|
1050
|
+
*
|
|
1051
|
+
* The `value` property contains the returned value or thrown error. If the function returned a `Promise`, then `result` will always be `'return'` even if the promise was rejected.
|
|
1052
|
+
*
|
|
1053
|
+
* @see https://vitest.dev/api/mock#mock-results
|
|
1054
|
+
* @example
|
|
1055
|
+
* const fn = vi.fn()
|
|
1056
|
+
* .mockReturnValueOnce('result')
|
|
1057
|
+
* .mockImplementationOnce(() => { throw new Error('thrown error') })
|
|
1058
|
+
*
|
|
1059
|
+
* const result = fn()
|
|
1060
|
+
*
|
|
1061
|
+
* try {
|
|
1062
|
+
* fn()
|
|
1063
|
+
* }
|
|
1064
|
+
* catch {}
|
|
1065
|
+
*
|
|
1066
|
+
* fn.mock.results === [
|
|
1067
|
+
* {
|
|
1068
|
+
* type: 'return',
|
|
1069
|
+
* value: 'result',
|
|
1070
|
+
* },
|
|
1071
|
+
* {
|
|
1072
|
+
* type: 'throw',
|
|
1073
|
+
* value: Error,
|
|
1074
|
+
* },
|
|
1075
|
+
* ]
|
|
1076
|
+
*/
|
|
1077
|
+
results: MockResult<ReturnType<T>>[];
|
|
1078
|
+
/**
|
|
1079
|
+
* An array containing all values that were `resolved` or `rejected` from the function.
|
|
1080
|
+
*
|
|
1081
|
+
* This array will be empty if the function was never resolved or rejected.
|
|
1082
|
+
*
|
|
1083
|
+
* @see https://vitest.dev/api/mock#mock-settledresults
|
|
1084
|
+
* @example
|
|
1085
|
+
* const fn = vi.fn().mockResolvedValueOnce('result')
|
|
1086
|
+
*
|
|
1087
|
+
* const result = fn()
|
|
1088
|
+
*
|
|
1089
|
+
* fn.mock.settledResults === []
|
|
1090
|
+
* fn.mock.results === [
|
|
1091
|
+
* {
|
|
1092
|
+
* type: 'return',
|
|
1093
|
+
* value: Promise<'result'>,
|
|
1094
|
+
* },
|
|
1095
|
+
* ]
|
|
1096
|
+
*
|
|
1097
|
+
* await result
|
|
1098
|
+
*
|
|
1099
|
+
* fn.mock.settledResults === [
|
|
1100
|
+
* {
|
|
1101
|
+
* type: 'fulfilled',
|
|
1102
|
+
* value: 'result',
|
|
1103
|
+
* },
|
|
1104
|
+
* ]
|
|
1105
|
+
*/
|
|
1106
|
+
settledResults: MockSettledResult<Awaited<ReturnType<T>>>[];
|
|
1107
|
+
/**
|
|
1108
|
+
* This contains the arguments of the last call. If spy wasn't called, will return `undefined`.
|
|
1109
|
+
* @see https://vitest.dev/api/mock#mock-lastcall
|
|
1110
|
+
*/
|
|
1111
|
+
lastCall: Parameters<T> | undefined;
|
|
1112
|
+
}
|
|
1113
|
+
|
|
1114
|
+
declare interface MockInstance<T extends Procedure = Procedure> extends Disposable {
|
|
1115
|
+
/**
|
|
1116
|
+
* Use it to return the name assigned to the mock with the `.mockName(name)` method. By default, it will return `vi.fn()`.
|
|
1117
|
+
* @see https://vitest.dev/api/mock#getmockname
|
|
1118
|
+
*/
|
|
1119
|
+
getMockName(): string;
|
|
1120
|
+
/**
|
|
1121
|
+
* Sets the internal mock name. This is useful for identifying the mock when an assertion fails.
|
|
1122
|
+
* @see https://vitest.dev/api/mock#mockname
|
|
1123
|
+
*/
|
|
1124
|
+
mockName(name: string): this;
|
|
1125
|
+
/**
|
|
1126
|
+
* Current context of the mock. It stores information about all invocation calls, instances, and results.
|
|
1127
|
+
*/
|
|
1128
|
+
mock: MockContext<T>;
|
|
1129
|
+
/**
|
|
1130
|
+
* Clears all information about every call. After calling it, all properties on `.mock` will return to their initial state. This method does not reset implementations. It is useful for cleaning up mocks between different assertions.
|
|
1131
|
+
*
|
|
1132
|
+
* To automatically call this method before each test, enable the [`clearMocks`](https://vitest.dev/config/#clearmocks) setting in the configuration.
|
|
1133
|
+
* @see https://vitest.dev/api/mock#mockclear
|
|
1134
|
+
*/
|
|
1135
|
+
mockClear(): this;
|
|
1136
|
+
/**
|
|
1137
|
+
* Does what `mockClear` does and resets inner implementation to the original function. This also resets all "once" implementations.
|
|
1138
|
+
*
|
|
1139
|
+
* Note that resetting a mock from `vi.fn()` will set implementation to an empty function that returns `undefined`.
|
|
1140
|
+
* Resetting a mock from `vi.fn(impl)` will set implementation to `impl`. It is useful for completely resetting a mock to its default state.
|
|
1141
|
+
*
|
|
1142
|
+
* To automatically call this method before each test, enable the [`mockReset`](https://vitest.dev/config/#mockreset) setting in the configuration.
|
|
1143
|
+
* @see https://vitest.dev/api/mock#mockreset
|
|
1144
|
+
*/
|
|
1145
|
+
mockReset(): this;
|
|
1146
|
+
/**
|
|
1147
|
+
* Does what `mockReset` does and restores original descriptors of spied-on objects.
|
|
1148
|
+
*
|
|
1149
|
+
* Note that restoring mock from `vi.fn()` will set implementation to an empty function that returns `undefined`. Restoring a `vi.fn(impl)` will restore implementation to `impl`.
|
|
1150
|
+
* @see https://vitest.dev/api/mock#mockrestore
|
|
1151
|
+
*/
|
|
1152
|
+
mockRestore(): void;
|
|
1153
|
+
/**
|
|
1154
|
+
* Returns current permanent mock implementation if there is one.
|
|
1155
|
+
*
|
|
1156
|
+
* If mock was created with `vi.fn`, it will consider passed down method as a mock implementation.
|
|
1157
|
+
*
|
|
1158
|
+
* If mock was created with `vi.spyOn`, it will return `undefined` unless a custom implementation was provided.
|
|
1159
|
+
*/
|
|
1160
|
+
getMockImplementation(): NormalizedProcedure<T> | undefined;
|
|
1161
|
+
/**
|
|
1162
|
+
* Accepts a function to be used as the mock implementation. TypeScript expects the arguments and return type to match those of the original function.
|
|
1163
|
+
* @see https://vitest.dev/api/mock#mockimplementation
|
|
1164
|
+
* @example
|
|
1165
|
+
* const increment = vi.fn().mockImplementation(count => count + 1);
|
|
1166
|
+
* expect(increment(3)).toBe(4);
|
|
1167
|
+
*/
|
|
1168
|
+
mockImplementation(fn: NormalizedProcedure<T>): this;
|
|
1169
|
+
/**
|
|
1170
|
+
* Accepts a function to be used as the mock implementation. TypeScript expects the arguments and return type to match those of the original function. This method can be chained to produce different results for multiple function calls.
|
|
1171
|
+
*
|
|
1172
|
+
* When the mocked function runs out of implementations, it will invoke the default implementation set with `vi.fn(() => defaultValue)` or `.mockImplementation(() => defaultValue)` if they were called.
|
|
1173
|
+
* @see https://vitest.dev/api/mock#mockimplementationonce
|
|
1174
|
+
* @example
|
|
1175
|
+
* const fn = vi.fn(count => count).mockImplementationOnce(count => count + 1);
|
|
1176
|
+
* expect(fn(3)).toBe(4);
|
|
1177
|
+
* expect(fn(3)).toBe(3);
|
|
1178
|
+
*/
|
|
1179
|
+
mockImplementationOnce(fn: NormalizedProcedure<T>): this;
|
|
1180
|
+
/**
|
|
1181
|
+
* Overrides the original mock implementation temporarily while the callback is being executed.
|
|
1182
|
+
*
|
|
1183
|
+
* Note that this method takes precedence over the [`mockImplementationOnce`](https://vitest.dev/api/mock#mockimplementationonce).
|
|
1184
|
+
* @see https://vitest.dev/api/mock#withimplementation
|
|
1185
|
+
* @example
|
|
1186
|
+
* const myMockFn = vi.fn(() => 'original')
|
|
1187
|
+
*
|
|
1188
|
+
* myMockFn.withImplementation(() => 'temp', () => {
|
|
1189
|
+
* myMockFn() // 'temp'
|
|
1190
|
+
* })
|
|
1191
|
+
*
|
|
1192
|
+
* myMockFn() // 'original'
|
|
1193
|
+
*/
|
|
1194
|
+
withImplementation<T2>(fn: NormalizedProcedure<T>, cb: () => T2): T2 extends Promise<unknown> ? Promise<this> : this;
|
|
1195
|
+
/**
|
|
1196
|
+
* Use this if you need to return the `this` context from the method without invoking the actual implementation.
|
|
1197
|
+
* @see https://vitest.dev/api/mock#mockreturnthis
|
|
1198
|
+
*/
|
|
1199
|
+
mockReturnThis(): this;
|
|
1200
|
+
/**
|
|
1201
|
+
* Accepts a value that will be returned whenever the mock function is called. TypeScript will only accept values that match the return type of the original function.
|
|
1202
|
+
* @see https://vitest.dev/api/mock#mockreturnvalue
|
|
1203
|
+
* @example
|
|
1204
|
+
* const mock = vi.fn()
|
|
1205
|
+
* mock.mockReturnValue(42)
|
|
1206
|
+
* mock() // 42
|
|
1207
|
+
* mock.mockReturnValue(43)
|
|
1208
|
+
* mock() // 43
|
|
1209
|
+
*/
|
|
1210
|
+
mockReturnValue(value: ReturnType<T>): this;
|
|
1211
|
+
/**
|
|
1212
|
+
* Accepts a value that will be returned whenever the mock function is called. TypeScript will only accept values that match the return type of the original function.
|
|
1213
|
+
*
|
|
1214
|
+
* When the mocked function runs out of implementations, it will invoke the default implementation set with `vi.fn(() => defaultValue)` or `.mockImplementation(() => defaultValue)` if they were called.
|
|
1215
|
+
* @example
|
|
1216
|
+
* const myMockFn = vi
|
|
1217
|
+
* .fn()
|
|
1218
|
+
* .mockReturnValue('default')
|
|
1219
|
+
* .mockReturnValueOnce('first call')
|
|
1220
|
+
* .mockReturnValueOnce('second call')
|
|
1221
|
+
*
|
|
1222
|
+
* // 'first call', 'second call', 'default'
|
|
1223
|
+
* console.log(myMockFn(), myMockFn(), myMockFn())
|
|
1224
|
+
*/
|
|
1225
|
+
mockReturnValueOnce(value: ReturnType<T>): this;
|
|
1226
|
+
/**
|
|
1227
|
+
* Accepts a value that will be resolved when the async function is called. TypeScript will only accept values that match the return type of the original function.
|
|
1228
|
+
* @example
|
|
1229
|
+
* const asyncMock = vi.fn().mockResolvedValue(42)
|
|
1230
|
+
* asyncMock() // Promise<42>
|
|
1231
|
+
*/
|
|
1232
|
+
mockResolvedValue(value: Awaited<ReturnType<T>>): this;
|
|
1233
|
+
/**
|
|
1234
|
+
* Accepts a value that will be resolved during the next function call. TypeScript will only accept values that match the return type of the original function. If chained, each consecutive call will resolve the specified value.
|
|
1235
|
+
* @example
|
|
1236
|
+
* const myMockFn = vi
|
|
1237
|
+
* .fn()
|
|
1238
|
+
* .mockResolvedValue('default')
|
|
1239
|
+
* .mockResolvedValueOnce('first call')
|
|
1240
|
+
* .mockResolvedValueOnce('second call')
|
|
1241
|
+
*
|
|
1242
|
+
* // Promise<'first call'>, Promise<'second call'>, Promise<'default'>
|
|
1243
|
+
* console.log(myMockFn(), myMockFn(), myMockFn())
|
|
1244
|
+
*/
|
|
1245
|
+
mockResolvedValueOnce(value: Awaited<ReturnType<T>>): this;
|
|
1246
|
+
/**
|
|
1247
|
+
* Accepts an error that will be rejected when async function is called.
|
|
1248
|
+
* @example
|
|
1249
|
+
* const asyncMock = vi.fn().mockRejectedValue(new Error('Async error'))
|
|
1250
|
+
* await asyncMock() // throws Error<'Async error'>
|
|
1251
|
+
*/
|
|
1252
|
+
mockRejectedValue(error: unknown): this;
|
|
1253
|
+
/**
|
|
1254
|
+
* Accepts a value that will be rejected during the next function call. If chained, each consecutive call will reject the specified value.
|
|
1255
|
+
* @example
|
|
1256
|
+
* const asyncMock = vi
|
|
1257
|
+
* .fn()
|
|
1258
|
+
* .mockResolvedValueOnce('first call')
|
|
1259
|
+
* .mockRejectedValueOnce(new Error('Async error'))
|
|
1260
|
+
*
|
|
1261
|
+
* await asyncMock() // first call
|
|
1262
|
+
* await asyncMock() // throws Error<'Async error'>
|
|
1263
|
+
*/
|
|
1264
|
+
mockRejectedValueOnce(error: unknown): this;
|
|
1265
|
+
}
|
|
1266
|
+
|
|
1267
|
+
declare type MockResult<T> = MockResultReturn<T> | MockResultThrow | MockResultIncomplete;
|
|
1268
|
+
|
|
1269
|
+
declare interface MockResultIncomplete {
|
|
1270
|
+
type: "incomplete";
|
|
1271
|
+
value: undefined;
|
|
1272
|
+
}
|
|
1273
|
+
|
|
1274
|
+
declare interface MockResultReturn<T> {
|
|
1275
|
+
type: "return";
|
|
1276
|
+
/**
|
|
1277
|
+
* The value that was returned from the function. If function returned a Promise, then this will be a resolved value.
|
|
1278
|
+
*/
|
|
1279
|
+
value: T;
|
|
1280
|
+
}
|
|
1281
|
+
|
|
1282
|
+
declare interface MockResultThrow {
|
|
1283
|
+
type: "throw";
|
|
1284
|
+
/**
|
|
1285
|
+
* An error that was thrown during function execution.
|
|
1286
|
+
*/
|
|
1287
|
+
value: any;
|
|
1288
|
+
}
|
|
1289
|
+
|
|
1290
|
+
declare type MockSettledResult<T> = MockSettledResultFulfilled<T> | MockSettledResultRejected;
|
|
1291
|
+
|
|
1292
|
+
declare interface MockSettledResultFulfilled<T> {
|
|
1293
|
+
type: "fulfilled";
|
|
1294
|
+
value: T;
|
|
1295
|
+
}
|
|
1296
|
+
|
|
1297
|
+
declare interface MockSettledResultRejected {
|
|
1298
|
+
type: "rejected";
|
|
1299
|
+
value: any;
|
|
1300
|
+
}
|
|
1301
|
+
|
|
216
1302
|
declare type NamesIndex = number;
|
|
217
1303
|
|
|
1304
|
+
declare interface NewPlugin {
|
|
1305
|
+
serialize: (val: any, config: Config, indentation: string, depth: number, refs: Refs, printer: Printer) => string;
|
|
1306
|
+
test: Test;
|
|
1307
|
+
}
|
|
1308
|
+
|
|
218
1309
|
declare type NormalizedConfig = Required<Omit<RstestConfig, OptionalKeys | 'pool'>> & {
|
|
219
1310
|
[key in OptionalKeys]?: RstestConfig[key];
|
|
220
1311
|
} & {
|
|
@@ -230,14 +1321,88 @@ declare type NormalizedFixture = {
|
|
|
230
1321
|
|
|
231
1322
|
declare type NormalizedFixtures = Record<string, NormalizedFixture>;
|
|
232
1323
|
|
|
1324
|
+
declare type NormalizedProcedure<T extends Procedure> = (...args: Parameters<T>) => ReturnType<T>;
|
|
1325
|
+
|
|
1326
|
+
declare interface OldPlugin {
|
|
1327
|
+
print: (val: unknown, print: Print, indent: Indent, options: PluginOptions, colors: Colors) => string;
|
|
1328
|
+
test: Test;
|
|
1329
|
+
}
|
|
1330
|
+
|
|
233
1331
|
declare type OptionalKeys = 'setupFiles' | 'testNamePattern' | 'plugins' | 'source' | 'resolve' | 'output' | 'performance' | 'tools' | 'dev' | 'onConsoleLog';
|
|
234
1332
|
|
|
235
|
-
declare type
|
|
236
|
-
|
|
1333
|
+
declare type OptionsReceived = PrettyFormatOptions;
|
|
1334
|
+
|
|
1335
|
+
declare interface ParsedStack {
|
|
1336
|
+
method: string;
|
|
1337
|
+
file: string;
|
|
1338
|
+
line: number;
|
|
1339
|
+
column: number;
|
|
1340
|
+
}
|
|
1341
|
+
|
|
1342
|
+
declare type Plugin_2 = NewPlugin | OldPlugin;
|
|
1343
|
+
|
|
1344
|
+
declare interface PluginOptions {
|
|
1345
|
+
edgeSpacing: string;
|
|
1346
|
+
min: boolean;
|
|
1347
|
+
spacing: string;
|
|
1348
|
+
}
|
|
1349
|
+
|
|
1350
|
+
declare type Plugins = Array<Plugin_2>;
|
|
1351
|
+
|
|
1352
|
+
declare interface PrettyFormatOptions {
|
|
1353
|
+
callToJSON?: boolean;
|
|
1354
|
+
escapeRegex?: boolean;
|
|
1355
|
+
escapeString?: boolean;
|
|
1356
|
+
highlight?: boolean;
|
|
1357
|
+
indent?: number;
|
|
1358
|
+
maxDepth?: number;
|
|
1359
|
+
maxWidth?: number;
|
|
1360
|
+
min?: boolean;
|
|
1361
|
+
printBasicPrototype?: boolean;
|
|
1362
|
+
printFunctionName?: boolean;
|
|
1363
|
+
compareKeys?: CompareKeys;
|
|
1364
|
+
plugins?: Plugins;
|
|
1365
|
+
}
|
|
1366
|
+
|
|
1367
|
+
declare type Print = (arg0: unknown) => string;
|
|
1368
|
+
|
|
1369
|
+
declare function printDiffOrStringify(received: unknown, expected: unknown, options?: DiffOptions): string | undefined;
|
|
1370
|
+
|
|
1371
|
+
declare type Printer = (val: unknown, config: Config, indentation: string, depth: number, refs: Refs, hasCalledToJSON?: boolean) => string;
|
|
1372
|
+
|
|
1373
|
+
declare function printExpected(value: unknown): string;
|
|
1374
|
+
|
|
1375
|
+
declare function printReceived(object: unknown): string;
|
|
1376
|
+
|
|
1377
|
+
declare function printWithType<T>(name: string, value: T, print: (value: T) => string): string;
|
|
1378
|
+
|
|
1379
|
+
declare type Procedure = (...args: any[]) => any;
|
|
1380
|
+
|
|
1381
|
+
declare type Promisify<O> = { [K in keyof O] : O[K] extends (...args: infer A) => infer R ? Promisify<O[K]> & ((...args: A) => Promise<R>) : O[K] };
|
|
1382
|
+
|
|
1383
|
+
declare type Promisify_2<O> = {
|
|
1384
|
+
[K in keyof O]: O[K] extends (...args: infer A) => infer R ? Promisify_2<O[K]> & ((...args: A) => Promise<R>) : O[K];
|
|
237
1385
|
};
|
|
238
1386
|
|
|
239
1387
|
declare type PromisifyAssertion<T> = Promisify<Assertion<T>>;
|
|
240
1388
|
|
|
1389
|
+
declare type PromisifyAssertion_2<T> = Promisify_2<Assertion_2<T>>;
|
|
1390
|
+
|
|
1391
|
+
declare interface RawMatcherFn<
|
|
1392
|
+
T extends MatcherState = MatcherState,
|
|
1393
|
+
E extends Array<any> = Array<any>
|
|
1394
|
+
> {
|
|
1395
|
+
(this: T, received: any, ...expected: E): ExpectationResult;
|
|
1396
|
+
}
|
|
1397
|
+
|
|
1398
|
+
declare interface RawSnapshotInfo {
|
|
1399
|
+
file: string;
|
|
1400
|
+
readonly?: boolean;
|
|
1401
|
+
content?: string;
|
|
1402
|
+
}
|
|
1403
|
+
|
|
1404
|
+
declare type Refs = Array<unknown>;
|
|
1405
|
+
|
|
241
1406
|
declare interface Reporter {
|
|
242
1407
|
/**
|
|
243
1408
|
* Called before test file run.
|
|
@@ -478,7 +1643,7 @@ declare type RstestPoolOptions = {
|
|
|
478
1643
|
declare type RstestPoolType = 'forks';
|
|
479
1644
|
|
|
480
1645
|
declare const runInPool: (options: RunWorkerOptions["options"]) => Promise<{
|
|
481
|
-
tests:
|
|
1646
|
+
tests: Test_2[];
|
|
482
1647
|
testPath: string;
|
|
483
1648
|
} | TestFileResult>;
|
|
484
1649
|
export default runInPool;
|
|
@@ -506,6 +1671,33 @@ declare type RunWorkerOptions = {
|
|
|
506
1671
|
rpcMethods: RuntimeRPC;
|
|
507
1672
|
};
|
|
508
1673
|
|
|
1674
|
+
declare interface SaveStatus {
|
|
1675
|
+
deleted: boolean;
|
|
1676
|
+
saved: boolean;
|
|
1677
|
+
}
|
|
1678
|
+
|
|
1679
|
+
declare interface SnapshotEnvironment {
|
|
1680
|
+
getVersion: () => string;
|
|
1681
|
+
getHeader: () => string;
|
|
1682
|
+
resolvePath: (filepath: string) => Promise<string>;
|
|
1683
|
+
resolveRawPath: (testPath: string, rawPath: string) => Promise<string>;
|
|
1684
|
+
saveSnapshotFile: (filepath: string, snapshot: string) => Promise<void>;
|
|
1685
|
+
readSnapshotFile: (filepath: string) => Promise<string | null>;
|
|
1686
|
+
removeSnapshotFile: (filepath: string) => Promise<void>;
|
|
1687
|
+
processStackTrace?: (stack: ParsedStack) => ParsedStack;
|
|
1688
|
+
}
|
|
1689
|
+
|
|
1690
|
+
declare class SnapshotManager {
|
|
1691
|
+
options: Omit<SnapshotStateOptions, "snapshotEnvironment">;
|
|
1692
|
+
summary: SnapshotSummary;
|
|
1693
|
+
extension: string;
|
|
1694
|
+
constructor(options: Omit<SnapshotStateOptions, "snapshotEnvironment">);
|
|
1695
|
+
clear(): void;
|
|
1696
|
+
add(result: SnapshotResult): void;
|
|
1697
|
+
resolvePath<T = any>(testPath: string, context?: T): string;
|
|
1698
|
+
resolveRawPath(testPath: string, rawPath: string): string;
|
|
1699
|
+
}
|
|
1700
|
+
|
|
509
1701
|
declare interface SnapshotMatcher<T> {
|
|
510
1702
|
<U extends {
|
|
511
1703
|
[P in keyof T]: any;
|
|
@@ -513,6 +1705,109 @@ declare interface SnapshotMatcher<T> {
|
|
|
513
1705
|
(message?: string): void;
|
|
514
1706
|
}
|
|
515
1707
|
|
|
1708
|
+
declare interface SnapshotMatchOptions {
|
|
1709
|
+
testId: string;
|
|
1710
|
+
testName: string;
|
|
1711
|
+
received: unknown;
|
|
1712
|
+
key?: string;
|
|
1713
|
+
inlineSnapshot?: string;
|
|
1714
|
+
isInline: boolean;
|
|
1715
|
+
error?: Error;
|
|
1716
|
+
rawSnapshot?: RawSnapshotInfo;
|
|
1717
|
+
}
|
|
1718
|
+
|
|
1719
|
+
declare interface SnapshotResult {
|
|
1720
|
+
filepath: string;
|
|
1721
|
+
added: number;
|
|
1722
|
+
fileDeleted: boolean;
|
|
1723
|
+
matched: number;
|
|
1724
|
+
unchecked: number;
|
|
1725
|
+
uncheckedKeys: Array<string>;
|
|
1726
|
+
unmatched: number;
|
|
1727
|
+
updated: number;
|
|
1728
|
+
}
|
|
1729
|
+
|
|
1730
|
+
declare interface SnapshotReturnOptions {
|
|
1731
|
+
actual: string;
|
|
1732
|
+
count: number;
|
|
1733
|
+
expected?: string;
|
|
1734
|
+
key: string;
|
|
1735
|
+
pass: boolean;
|
|
1736
|
+
}
|
|
1737
|
+
|
|
1738
|
+
declare class SnapshotState {
|
|
1739
|
+
testFilePath: string;
|
|
1740
|
+
snapshotPath: string;
|
|
1741
|
+
private _counters;
|
|
1742
|
+
private _dirty;
|
|
1743
|
+
private _updateSnapshot;
|
|
1744
|
+
private _snapshotData;
|
|
1745
|
+
private _initialData;
|
|
1746
|
+
private _inlineSnapshots;
|
|
1747
|
+
private _inlineSnapshotStacks;
|
|
1748
|
+
private _testIdToKeys;
|
|
1749
|
+
private _rawSnapshots;
|
|
1750
|
+
private _uncheckedKeys;
|
|
1751
|
+
private _snapshotFormat;
|
|
1752
|
+
private _environment;
|
|
1753
|
+
private _fileExists;
|
|
1754
|
+
expand: boolean;
|
|
1755
|
+
// getter/setter for jest-image-snapshot compat
|
|
1756
|
+
// https://github.com/vitest-dev/vitest/issues/7322
|
|
1757
|
+
private _added;
|
|
1758
|
+
private _matched;
|
|
1759
|
+
private _unmatched;
|
|
1760
|
+
private _updated;
|
|
1761
|
+
get added(): CounterMap<string>;
|
|
1762
|
+
set added(value: CounterMap<string>);
|
|
1763
|
+
get matched(): CounterMap<string>;
|
|
1764
|
+
set matched(value: CounterMap<string>);
|
|
1765
|
+
get unmatched(): CounterMap<string>;
|
|
1766
|
+
set unmatched(value: CounterMap<string>);
|
|
1767
|
+
get updated(): CounterMap<string>;
|
|
1768
|
+
set updated(value: CounterMap<string>);
|
|
1769
|
+
private constructor();
|
|
1770
|
+
static create(testFilePath: string, options: SnapshotStateOptions): Promise<SnapshotState>;
|
|
1771
|
+
get environment(): SnapshotEnvironment;
|
|
1772
|
+
markSnapshotsAsCheckedForTest(testName: string): void;
|
|
1773
|
+
clearTest(testId: string): void;
|
|
1774
|
+
protected _inferInlineSnapshotStack(stacks: ParsedStack[]): ParsedStack | null;
|
|
1775
|
+
private _addSnapshot;
|
|
1776
|
+
save(): Promise<SaveStatus>;
|
|
1777
|
+
getUncheckedCount(): number;
|
|
1778
|
+
getUncheckedKeys(): Array<string>;
|
|
1779
|
+
removeUncheckedKeys(): void;
|
|
1780
|
+
match({ testId, testName, received, key, inlineSnapshot, isInline, error, rawSnapshot }: SnapshotMatchOptions): SnapshotReturnOptions;
|
|
1781
|
+
pack(): Promise<SnapshotResult>;
|
|
1782
|
+
}
|
|
1783
|
+
|
|
1784
|
+
declare interface SnapshotStateOptions {
|
|
1785
|
+
updateSnapshot: SnapshotUpdateState;
|
|
1786
|
+
snapshotEnvironment: SnapshotEnvironment;
|
|
1787
|
+
expand?: boolean;
|
|
1788
|
+
snapshotFormat?: OptionsReceived;
|
|
1789
|
+
resolveSnapshotPath?: (path: string, extension: string, context?: any) => string;
|
|
1790
|
+
}
|
|
1791
|
+
|
|
1792
|
+
declare interface SnapshotSummary {
|
|
1793
|
+
added: number;
|
|
1794
|
+
didUpdate: boolean;
|
|
1795
|
+
failure: boolean;
|
|
1796
|
+
filesAdded: number;
|
|
1797
|
+
filesRemoved: number;
|
|
1798
|
+
filesRemovedList: Array<string>;
|
|
1799
|
+
filesUnmatched: number;
|
|
1800
|
+
filesUpdated: number;
|
|
1801
|
+
matched: number;
|
|
1802
|
+
total: number;
|
|
1803
|
+
unchecked: number;
|
|
1804
|
+
uncheckedKeysByFile: Array<UncheckedSnapshot>;
|
|
1805
|
+
unmatched: number;
|
|
1806
|
+
updated: number;
|
|
1807
|
+
}
|
|
1808
|
+
|
|
1809
|
+
declare type SnapshotUpdateState = "all" | "new" | "none";
|
|
1810
|
+
|
|
516
1811
|
declare type SourceColumn = number;
|
|
517
1812
|
|
|
518
1813
|
declare type SourceLine = number;
|
|
@@ -555,10 +1850,23 @@ declare class StatusRenderer {
|
|
|
555
1850
|
clear(): void;
|
|
556
1851
|
}
|
|
557
1852
|
|
|
1853
|
+
declare function stringify(object: unknown, maxDepth?: number, { maxLength,...options }?: StringifyOptions): string;
|
|
1854
|
+
|
|
1855
|
+
declare interface StringifyOptions extends PrettyFormatOptions {
|
|
1856
|
+
maxLength?: number;
|
|
1857
|
+
}
|
|
1858
|
+
|
|
558
1859
|
declare type SuiteContext = {
|
|
559
1860
|
filepath: TestPath;
|
|
560
1861
|
};
|
|
561
1862
|
|
|
1863
|
+
declare interface SyncExpectationResult {
|
|
1864
|
+
pass: boolean;
|
|
1865
|
+
message: () => string;
|
|
1866
|
+
actual?: any;
|
|
1867
|
+
expected?: any;
|
|
1868
|
+
}
|
|
1869
|
+
|
|
562
1870
|
declare interface TaskResult {
|
|
563
1871
|
/**
|
|
564
1872
|
* State of the task. Inherits the `task.mode` during collection.
|
|
@@ -576,7 +1884,9 @@ declare interface TaskResult {
|
|
|
576
1884
|
|
|
577
1885
|
declare type TaskState = 'pass' | 'fail';
|
|
578
1886
|
|
|
579
|
-
declare type Test =
|
|
1887
|
+
declare type Test = (arg0: any) => boolean;
|
|
1888
|
+
|
|
1889
|
+
declare type Test_2 = TestSuite | TestCase;
|
|
580
1890
|
|
|
581
1891
|
declare type TestCase = {
|
|
582
1892
|
testPath: TestPath;
|
|
@@ -610,6 +1920,12 @@ declare type TestContext = {
|
|
|
610
1920
|
expect: RstestExpect;
|
|
611
1921
|
};
|
|
612
1922
|
|
|
1923
|
+
declare type Tester = (this: TesterContext, a: any, b: any, customTesters: Array<Tester>) => boolean | undefined;
|
|
1924
|
+
|
|
1925
|
+
declare interface TesterContext {
|
|
1926
|
+
equals: (a: unknown, b: unknown, customTesters?: Array<Tester>, strictCheck?: boolean) => boolean;
|
|
1927
|
+
}
|
|
1928
|
+
|
|
613
1929
|
declare type TestFileInfo = {
|
|
614
1930
|
testPath: TestPath;
|
|
615
1931
|
};
|
|
@@ -671,6 +1987,11 @@ declare class TraceMap implements SourceMap {
|
|
|
671
1987
|
constructor(map: Ro<SourceMapInput>, mapUrl?: string | null);
|
|
672
1988
|
}
|
|
673
1989
|
|
|
1990
|
+
declare interface UncheckedSnapshot {
|
|
1991
|
+
filePath: string;
|
|
1992
|
+
keys: Array<string>;
|
|
1993
|
+
}
|
|
1994
|
+
|
|
674
1995
|
declare type Use<T> = (value: T) => Promise<void>;
|
|
675
1996
|
|
|
676
1997
|
declare interface UserConsoleLog {
|
|
@@ -685,6 +2006,13 @@ declare class VerboseReporter extends DefaultReporter {
|
|
|
685
2006
|
onTestFileResult(test: TestFileResult): void;
|
|
686
2007
|
}
|
|
687
2008
|
|
|
2009
|
+
declare type VitestAssertion<
|
|
2010
|
+
A,
|
|
2011
|
+
T
|
|
2012
|
+
> = { [K in keyof A] : A[K] extends Chai.Assertion ? Assertion<T> : A[K] extends (...args: any[]) => any ? A[K] : VitestAssertion<A[K], T> } & ((type: string, message?: string) => Assertion);
|
|
2013
|
+
|
|
2014
|
+
declare type WithAsymmetricMatcher<T> = T | AsymmetricMatcher<unknown>;
|
|
2015
|
+
|
|
688
2016
|
declare type WorkerContext = {
|
|
689
2017
|
rootPath: RstestContext['rootPath'];
|
|
690
2018
|
runtimeConfig: RuntimeConfig;
|