@rstest/core 0.1.0 → 0.1.1
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} +63 -5
- package/dist/44.js +2 -0
- package/dist/443.js +1210 -0
- package/dist/562.js +3 -1
- 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/867.js +58 -44
- package/dist/965.js +2 -0
- package/dist/cli.js +13 -15
- 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 +6 -7
- package/dist/81.js +0 -1467
package/dist-types/public.d.ts
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
import type { addSerializer } from '@vitest/snapshot';
|
|
2
1
|
import type { assert as assert_2 } from 'chai';
|
|
3
|
-
import type { Assertion as Assertion_2 } from '@vitest/expect';
|
|
4
|
-
import type { ExpectStatic as ExpectStatic_2 } from '@vitest/expect';
|
|
5
|
-
import type { MatcherState as MatcherState_2 } from '@vitest/expect';
|
|
6
2
|
import type { RsbuildConfig } from '@rsbuild/core';
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
|
|
6
|
+
*
|
|
7
|
+
* This source code is licensed under the MIT license found in the
|
|
8
|
+
* LICENSE file in the root directory of this source tree.
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
declare function addSerializer(plugin: Plugin_2): void;
|
|
12
12
|
|
|
13
13
|
export declare const afterAll: Rstest['afterAll'];
|
|
14
14
|
|
|
@@ -62,16 +62,189 @@ export declare interface Assertion<T = any> extends Assertion_2<T> {
|
|
|
62
62
|
* @example
|
|
63
63
|
* await expect(someAsyncFunc).resolves.toBe(42);
|
|
64
64
|
*/
|
|
65
|
-
resolves:
|
|
65
|
+
resolves: PromisifyAssertion_2<T>;
|
|
66
66
|
/**
|
|
67
67
|
* Verifies that a promise rejects.
|
|
68
68
|
*
|
|
69
69
|
* @example
|
|
70
70
|
* await expect(someAsyncFunc).rejects.toThrow('error');
|
|
71
71
|
*/
|
|
72
|
-
rejects:
|
|
72
|
+
rejects: PromisifyAssertion_2<T>;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
declare interface Assertion_2<T = any> extends VitestAssertion<Chai.Assertion, T>, JestAssertion<T>, Matchers<T> {
|
|
76
|
+
/**
|
|
77
|
+
* Ensures a value is of a specific type.
|
|
78
|
+
*
|
|
79
|
+
* @example
|
|
80
|
+
* expect(value).toBeTypeOf('string');
|
|
81
|
+
* expect(number).toBeTypeOf('number');
|
|
82
|
+
*/
|
|
83
|
+
toBeTypeOf: (expected: "bigint" | "boolean" | "function" | "number" | "object" | "string" | "symbol" | "undefined") => void;
|
|
84
|
+
/**
|
|
85
|
+
* Asserts that a mock function was called exactly once.
|
|
86
|
+
*
|
|
87
|
+
* @example
|
|
88
|
+
* expect(mockFunc).toHaveBeenCalledOnce();
|
|
89
|
+
*/
|
|
90
|
+
toHaveBeenCalledOnce: () => void;
|
|
91
|
+
/**
|
|
92
|
+
* Ensure that a mock function is called with specific arguments and called
|
|
93
|
+
* exactly once.
|
|
94
|
+
*
|
|
95
|
+
* @example
|
|
96
|
+
* expect(mockFunc).toHaveBeenCalledExactlyOnceWith('arg1', 42);
|
|
97
|
+
*/
|
|
98
|
+
toHaveBeenCalledExactlyOnceWith: <E extends any[]>(...args: E) => void;
|
|
99
|
+
/**
|
|
100
|
+
* This assertion checks if a `Mock` was called before another `Mock`.
|
|
101
|
+
* @param mock - A mock function created by `vi.spyOn` or `vi.fn`
|
|
102
|
+
* @param failIfNoFirstInvocation - Fail if the first mock was never called
|
|
103
|
+
* @example
|
|
104
|
+
* const mock1 = vi.fn()
|
|
105
|
+
* const mock2 = vi.fn()
|
|
106
|
+
*
|
|
107
|
+
* mock1()
|
|
108
|
+
* mock2()
|
|
109
|
+
* mock1()
|
|
110
|
+
*
|
|
111
|
+
* expect(mock1).toHaveBeenCalledBefore(mock2)
|
|
112
|
+
*/
|
|
113
|
+
toHaveBeenCalledBefore: (mock: MockInstance, failIfNoFirstInvocation?: boolean) => void;
|
|
114
|
+
/**
|
|
115
|
+
* This assertion checks if a `Mock` was called after another `Mock`.
|
|
116
|
+
* @param mock - A mock function created by `vi.spyOn` or `vi.fn`
|
|
117
|
+
* @param failIfNoFirstInvocation - Fail if the first mock was never called
|
|
118
|
+
* @example
|
|
119
|
+
* const mock1 = vi.fn()
|
|
120
|
+
* const mock2 = vi.fn()
|
|
121
|
+
*
|
|
122
|
+
* mock2()
|
|
123
|
+
* mock1()
|
|
124
|
+
* mock2()
|
|
125
|
+
*
|
|
126
|
+
* expect(mock1).toHaveBeenCalledAfter(mock2)
|
|
127
|
+
*/
|
|
128
|
+
toHaveBeenCalledAfter: (mock: MockInstance, failIfNoFirstInvocation?: boolean) => void;
|
|
129
|
+
/**
|
|
130
|
+
* Checks that a promise resolves successfully at least once.
|
|
131
|
+
*
|
|
132
|
+
* @example
|
|
133
|
+
* await expect(promise).toHaveResolved();
|
|
134
|
+
*/
|
|
135
|
+
toHaveResolved: () => void;
|
|
136
|
+
/**
|
|
137
|
+
* Checks that a promise resolves to a specific value.
|
|
138
|
+
*
|
|
139
|
+
* @example
|
|
140
|
+
* await expect(promise).toHaveResolvedWith('success');
|
|
141
|
+
*/
|
|
142
|
+
toHaveResolvedWith: <E>(value: E) => void;
|
|
143
|
+
/**
|
|
144
|
+
* Ensures a promise resolves a specific number of times.
|
|
145
|
+
*
|
|
146
|
+
* @example
|
|
147
|
+
* expect(mockAsyncFunc).toHaveResolvedTimes(3);
|
|
148
|
+
*/
|
|
149
|
+
toHaveResolvedTimes: (times: number) => void;
|
|
150
|
+
/**
|
|
151
|
+
* Asserts that the last resolved value of a promise matches an expected value.
|
|
152
|
+
*
|
|
153
|
+
* @example
|
|
154
|
+
* await expect(mockAsyncFunc).toHaveLastResolvedWith('finalResult');
|
|
155
|
+
*/
|
|
156
|
+
toHaveLastResolvedWith: <E>(value: E) => void;
|
|
157
|
+
/**
|
|
158
|
+
* Ensures a specific value was returned by a promise on the nth resolution.
|
|
159
|
+
*
|
|
160
|
+
* @example
|
|
161
|
+
* await expect(mockAsyncFunc).toHaveNthResolvedWith(2, 'secondResult');
|
|
162
|
+
*/
|
|
163
|
+
toHaveNthResolvedWith: <E>(nthCall: number, value: E) => void;
|
|
164
|
+
/**
|
|
165
|
+
* Verifies that a promise resolves.
|
|
166
|
+
*
|
|
167
|
+
* @example
|
|
168
|
+
* await expect(someAsyncFunc).resolves.toBe(42);
|
|
169
|
+
*/
|
|
170
|
+
resolves: PromisifyAssertion<T>;
|
|
171
|
+
/**
|
|
172
|
+
* Verifies that a promise rejects.
|
|
173
|
+
*
|
|
174
|
+
* @example
|
|
175
|
+
* await expect(someAsyncFunc).rejects.toThrow('error');
|
|
176
|
+
*/
|
|
177
|
+
rejects: PromisifyAssertion<T>;
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
declare abstract class AsymmetricMatcher<
|
|
181
|
+
T,
|
|
182
|
+
State extends MatcherState = MatcherState
|
|
183
|
+
> implements AsymmetricMatcherInterface {
|
|
184
|
+
protected sample: T;
|
|
185
|
+
protected inverse: boolean;
|
|
186
|
+
// should have "jest" to be compatible with its ecosystem
|
|
187
|
+
$$typeof: symbol;
|
|
188
|
+
constructor(sample: T, inverse?: boolean);
|
|
189
|
+
protected getMatcherContext(expect?: Chai.ExpectStatic): State;
|
|
190
|
+
abstract asymmetricMatch(other: unknown): boolean;
|
|
191
|
+
abstract toString(): string;
|
|
192
|
+
getExpectedType?(): string;
|
|
193
|
+
toAsymmetricMatcher?(): string;
|
|
73
194
|
}
|
|
74
195
|
|
|
196
|
+
declare interface AsymmetricMatcherInterface {
|
|
197
|
+
asymmetricMatch: (other: unknown) => boolean;
|
|
198
|
+
toString: () => string;
|
|
199
|
+
getExpectedType?: () => string;
|
|
200
|
+
toAsymmetricMatcher?: () => string;
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
declare interface AsymmetricMatchersContaining extends CustomMatcher {
|
|
204
|
+
/**
|
|
205
|
+
* Matches if the received string contains the expected substring.
|
|
206
|
+
*
|
|
207
|
+
* @example
|
|
208
|
+
* expect('I have an apple').toEqual(expect.stringContaining('apple'));
|
|
209
|
+
* expect({ a: 'test string' }).toEqual({ a: expect.stringContaining('test') });
|
|
210
|
+
*/
|
|
211
|
+
stringContaining: (expected: string) => any;
|
|
212
|
+
/**
|
|
213
|
+
* Matches if the received object contains all properties of the expected object.
|
|
214
|
+
*
|
|
215
|
+
* @example
|
|
216
|
+
* expect({ a: '1', b: 2 }).toEqual(expect.objectContaining({ a: '1' }))
|
|
217
|
+
*/
|
|
218
|
+
objectContaining: <T = any>(expected: DeeplyAllowMatchers<T>) => any;
|
|
219
|
+
/**
|
|
220
|
+
* Matches if the received array contains all elements in the expected array.
|
|
221
|
+
*
|
|
222
|
+
* @example
|
|
223
|
+
* expect(['a', 'b', 'c']).toEqual(expect.arrayContaining(['b', 'a']));
|
|
224
|
+
*/
|
|
225
|
+
arrayContaining: <T = unknown>(expected: Array<DeeplyAllowMatchers<T>>) => any;
|
|
226
|
+
/**
|
|
227
|
+
* Matches if the received string or regex matches the expected pattern.
|
|
228
|
+
*
|
|
229
|
+
* @example
|
|
230
|
+
* expect('hello world').toEqual(expect.stringMatching(/^hello/));
|
|
231
|
+
* expect('hello world').toEqual(expect.stringMatching('hello'));
|
|
232
|
+
*/
|
|
233
|
+
stringMatching: (expected: string | RegExp) => any;
|
|
234
|
+
/**
|
|
235
|
+
* Matches if the received number is within a certain precision of the expected number.
|
|
236
|
+
*
|
|
237
|
+
* @param precision - Optional decimal precision for comparison. Default is 2.
|
|
238
|
+
*
|
|
239
|
+
* @example
|
|
240
|
+
* expect(10.45).toEqual(expect.closeTo(10.5, 1));
|
|
241
|
+
* expect(5.11).toEqual(expect.closeTo(5.12)); // with default precision
|
|
242
|
+
*/
|
|
243
|
+
closeTo: (expected: number, precision?: number) => any;
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
declare type AsyncExpectationResult = Promise<SyncExpectationResult>;
|
|
247
|
+
|
|
75
248
|
export declare const beforeAll: Rstest['beforeAll'];
|
|
76
249
|
|
|
77
250
|
declare type BeforeAllListener = (ctx: SuiteContext) => MaybePromise<void | AfterAllListener>;
|
|
@@ -86,12 +259,118 @@ declare type BuiltinReporterOptions = {
|
|
|
86
259
|
default: DefaultReporterOptions;
|
|
87
260
|
};
|
|
88
261
|
|
|
262
|
+
/**
|
|
263
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
264
|
+
*
|
|
265
|
+
* This source code is licensed under the MIT license found in the
|
|
266
|
+
* LICENSE file in the root directory of this source tree.
|
|
267
|
+
*/
|
|
268
|
+
declare interface Colors {
|
|
269
|
+
comment: {
|
|
270
|
+
close: string
|
|
271
|
+
open: string
|
|
272
|
+
};
|
|
273
|
+
content: {
|
|
274
|
+
close: string
|
|
275
|
+
open: string
|
|
276
|
+
};
|
|
277
|
+
prop: {
|
|
278
|
+
close: string
|
|
279
|
+
open: string
|
|
280
|
+
};
|
|
281
|
+
tag: {
|
|
282
|
+
close: string
|
|
283
|
+
open: string
|
|
284
|
+
};
|
|
285
|
+
value: {
|
|
286
|
+
close: string
|
|
287
|
+
open: string
|
|
288
|
+
};
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
declare type CompareKeys = ((a: string, b: string) => number) | null | undefined;
|
|
292
|
+
|
|
293
|
+
declare interface Config {
|
|
294
|
+
callToJSON: boolean;
|
|
295
|
+
compareKeys: CompareKeys;
|
|
296
|
+
colors: Colors;
|
|
297
|
+
escapeRegex: boolean;
|
|
298
|
+
escapeString: boolean;
|
|
299
|
+
indent: string;
|
|
300
|
+
maxDepth: number;
|
|
301
|
+
maxWidth: number;
|
|
302
|
+
min: boolean;
|
|
303
|
+
plugins: Plugins;
|
|
304
|
+
printBasicPrototype: boolean;
|
|
305
|
+
printFunctionName: boolean;
|
|
306
|
+
spacingInner: string;
|
|
307
|
+
spacingOuter: string;
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
declare interface Constructable {
|
|
311
|
+
new (...args: any[]): any;
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
declare class CounterMap<K> extends DefaultMap<K, number> {
|
|
315
|
+
constructor();
|
|
316
|
+
// compat for jest-image-snapshot https://github.com/vitest-dev/vitest/issues/7322
|
|
317
|
+
// `valueOf` and `Snapshot.added` setter allows
|
|
318
|
+
// snapshotState.added = snapshotState.added + 1
|
|
319
|
+
// to function as
|
|
320
|
+
// snapshotState.added.total_ = snapshotState.added.total() + 1
|
|
321
|
+
_total: number | undefined;
|
|
322
|
+
valueOf(): number;
|
|
323
|
+
increment(key: K): void;
|
|
324
|
+
total(): number;
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
declare interface CustomMatcher {
|
|
328
|
+
/**
|
|
329
|
+
* Checks that a value satisfies a custom matcher function.
|
|
330
|
+
*
|
|
331
|
+
* @param matcher - A function returning a boolean based on the custom condition
|
|
332
|
+
* @param message - Optional custom error message on failure
|
|
333
|
+
*
|
|
334
|
+
* @example
|
|
335
|
+
* expect(age).toSatisfy(val => val >= 18, 'Age must be at least 18');
|
|
336
|
+
* expect(age).toEqual(expect.toSatisfy(val => val >= 18, 'Age must be at least 18'));
|
|
337
|
+
*/
|
|
338
|
+
toSatisfy: (matcher: (value: any) => boolean, message?: string) => any;
|
|
339
|
+
/**
|
|
340
|
+
* Matches if the received value is one of the values in the expected array.
|
|
341
|
+
*
|
|
342
|
+
* @example
|
|
343
|
+
* expect(1).toBeOneOf([1, 2, 3])
|
|
344
|
+
* expect('foo').toBeOneOf([expect.any(String)])
|
|
345
|
+
* expect({ a: 1 }).toEqual({ a: expect.toBeOneOf(['1', '2', '3']) })
|
|
346
|
+
*/
|
|
347
|
+
toBeOneOf: <T>(sample: Array<T>) => any;
|
|
348
|
+
}
|
|
349
|
+
|
|
89
350
|
declare interface DecodedSourceMap extends SourceMapV3 {
|
|
90
351
|
mappings: SourceMapSegment[][];
|
|
91
352
|
}
|
|
92
353
|
|
|
93
354
|
declare type DecodedSourceMapXInput = DecodedSourceMap & XInput;
|
|
94
355
|
|
|
356
|
+
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>;
|
|
357
|
+
|
|
358
|
+
/**
|
|
359
|
+
* Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
|
|
360
|
+
*
|
|
361
|
+
* This source code is licensed under the MIT license found in the
|
|
362
|
+
* LICENSE file in the root directory of this source tree.
|
|
363
|
+
*/
|
|
364
|
+
|
|
365
|
+
declare class DefaultMap<
|
|
366
|
+
K,
|
|
367
|
+
V
|
|
368
|
+
> extends Map<K, V> {
|
|
369
|
+
private defaultFn;
|
|
370
|
+
constructor(defaultFn: (key: K) => V, entries?: Iterable<readonly [K, V]>);
|
|
371
|
+
get(key: K): V;
|
|
372
|
+
}
|
|
373
|
+
|
|
95
374
|
declare class DefaultReporter implements Reporter {
|
|
96
375
|
protected rootPath: string;
|
|
97
376
|
protected config: NormalizedConfig;
|
|
@@ -159,6 +438,49 @@ declare type DescribeFn = (description: string, fn?: () => void) => void;
|
|
|
159
438
|
|
|
160
439
|
declare type DescribeForFn = <T>(cases: ReadonlyArray<T>) => (description: string, fn?: (param: T) => MaybePromise<void>) => void;
|
|
161
440
|
|
|
441
|
+
/**
|
|
442
|
+
* @param a Expected value
|
|
443
|
+
* @param b Received value
|
|
444
|
+
* @param options Diff options
|
|
445
|
+
* @returns {string | null} a string diff
|
|
446
|
+
*/
|
|
447
|
+
declare function diff(a: any, b: any, options?: DiffOptions): string | undefined;
|
|
448
|
+
|
|
449
|
+
declare interface DiffOptions {
|
|
450
|
+
aAnnotation?: string;
|
|
451
|
+
aColor?: DiffOptionsColor;
|
|
452
|
+
aIndicator?: string;
|
|
453
|
+
bAnnotation?: string;
|
|
454
|
+
bColor?: DiffOptionsColor;
|
|
455
|
+
bIndicator?: string;
|
|
456
|
+
changeColor?: DiffOptionsColor;
|
|
457
|
+
changeLineTrailingSpaceColor?: DiffOptionsColor;
|
|
458
|
+
commonColor?: DiffOptionsColor;
|
|
459
|
+
commonIndicator?: string;
|
|
460
|
+
commonLineTrailingSpaceColor?: DiffOptionsColor;
|
|
461
|
+
contextLines?: number;
|
|
462
|
+
emptyFirstOrLastLinePlaceholder?: string;
|
|
463
|
+
expand?: boolean;
|
|
464
|
+
includeChangeCounts?: boolean;
|
|
465
|
+
omitAnnotationLines?: boolean;
|
|
466
|
+
patchColor?: DiffOptionsColor;
|
|
467
|
+
printBasicPrototype?: boolean;
|
|
468
|
+
maxDepth?: number;
|
|
469
|
+
compareKeys?: CompareKeys;
|
|
470
|
+
truncateThreshold?: number;
|
|
471
|
+
truncateAnnotation?: string;
|
|
472
|
+
truncateAnnotationColor?: DiffOptionsColor;
|
|
473
|
+
}
|
|
474
|
+
|
|
475
|
+
/**
|
|
476
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
477
|
+
*
|
|
478
|
+
* This source code is licensed under the MIT license found in the
|
|
479
|
+
* LICENSE file in the root directory of this source tree.
|
|
480
|
+
*/
|
|
481
|
+
|
|
482
|
+
declare type DiffOptionsColor = (arg: string) => string;
|
|
483
|
+
|
|
162
484
|
declare type Duration = {
|
|
163
485
|
totalTime: number;
|
|
164
486
|
buildTime: number;
|
|
@@ -173,6 +495,8 @@ declare type EncodedSourceMapXInput = EncodedSourceMap & XInput;
|
|
|
173
495
|
|
|
174
496
|
export declare const expect: Rstest['expect'];
|
|
175
497
|
|
|
498
|
+
declare type ExpectationResult = SyncExpectationResult | AsyncExpectationResult;
|
|
499
|
+
|
|
176
500
|
declare interface ExpectPollOptions {
|
|
177
501
|
/**
|
|
178
502
|
* @default 50
|
|
@@ -189,13 +513,23 @@ declare interface ExpectStatic extends ExpectStatic_2 {
|
|
|
189
513
|
<T>(actual: T, message?: string): Assertion<T>;
|
|
190
514
|
unreachable: (message?: string) => never;
|
|
191
515
|
soft: <T>(actual: T, message?: string) => Assertion<T>;
|
|
192
|
-
poll: <T>(actual: () => T, options?: ExpectPollOptions) => Omit<
|
|
516
|
+
poll: <T>(actual: () => T, options?: ExpectPollOptions) => Omit<PromisifyAssertion_2<Awaited<T>>, 'rejects' | 'resolves' | 'toThrow' | 'toThrowError' | 'throw' | 'throws' | 'matchSnapshot' | 'toMatchSnapshot' | 'toMatchInlineSnapshot' | 'toThrowErrorMatchingSnapshot' | 'toThrowErrorMatchingInlineSnapshot'>;
|
|
193
517
|
addEqualityTesters: (testers: Array<Tester>) => void;
|
|
194
518
|
assertions: (expected: number) => void;
|
|
195
519
|
hasAssertions: () => void;
|
|
196
520
|
addSnapshotSerializer: typeof addSerializer;
|
|
197
|
-
getState: () =>
|
|
198
|
-
setState: (state: Partial<
|
|
521
|
+
getState: () => MatcherState_2;
|
|
522
|
+
setState: (state: Partial<MatcherState_2>) => void;
|
|
523
|
+
}
|
|
524
|
+
|
|
525
|
+
declare interface ExpectStatic_2 extends Chai.ExpectStatic, Matchers, AsymmetricMatchersContaining {
|
|
526
|
+
<T>(actual: T, message?: string): Assertion_2<T>;
|
|
527
|
+
extend: (expects: MatchersObject) => void;
|
|
528
|
+
anything: () => any;
|
|
529
|
+
any: (constructor: unknown) => any;
|
|
530
|
+
getState: () => MatcherState;
|
|
531
|
+
setState: (state: Partial<MatcherState>) => void;
|
|
532
|
+
not: AsymmetricMatchersContaining;
|
|
199
533
|
}
|
|
200
534
|
|
|
201
535
|
/**
|
|
@@ -277,10 +611,30 @@ declare type FormattedError = {
|
|
|
277
611
|
diff?: string;
|
|
278
612
|
};
|
|
279
613
|
|
|
614
|
+
declare interface Formatter {
|
|
615
|
+
(input?: unknown): string;
|
|
616
|
+
open: string;
|
|
617
|
+
close: string;
|
|
618
|
+
}
|
|
619
|
+
|
|
280
620
|
declare type FunctionLike = (...args: any) => any;
|
|
281
621
|
|
|
282
622
|
declare type GeneratedColumn = number;
|
|
283
623
|
|
|
624
|
+
declare function getMatcherUtils(): {
|
|
625
|
+
EXPECTED_COLOR: Formatter
|
|
626
|
+
RECEIVED_COLOR: Formatter
|
|
627
|
+
INVERTED_COLOR: Formatter
|
|
628
|
+
BOLD_WEIGHT: Formatter
|
|
629
|
+
DIM_COLOR: Formatter
|
|
630
|
+
diff: typeof diff
|
|
631
|
+
matcherHint: typeof matcherHint
|
|
632
|
+
printReceived: typeof printReceived
|
|
633
|
+
printExpected: typeof printExpected
|
|
634
|
+
printDiffOrStringify: typeof printDiffOrStringify
|
|
635
|
+
printWithType: typeof printWithType
|
|
636
|
+
};
|
|
637
|
+
|
|
284
638
|
declare type GetSourcemap = (sourcePath: string) => SourceMapInput | null;
|
|
285
639
|
|
|
286
640
|
declare class GithubActionsReporter {
|
|
@@ -301,6 +655,8 @@ declare class GithubActionsReporter {
|
|
|
301
655
|
}): Promise<void>;
|
|
302
656
|
}
|
|
303
657
|
|
|
658
|
+
declare type Indent = (arg0: string) => string;
|
|
659
|
+
|
|
304
660
|
declare interface InlineSnapshotMatcher<T> {
|
|
305
661
|
<U extends {
|
|
306
662
|
[P in keyof T]: any;
|
|
@@ -310,19 +666,562 @@ declare interface InlineSnapshotMatcher<T> {
|
|
|
310
666
|
|
|
311
667
|
export declare const it: Rstest['it'];
|
|
312
668
|
|
|
313
|
-
declare interface
|
|
669
|
+
declare interface JestAssertion<T = any> extends jest.Matchers<void, T>, CustomMatcher {
|
|
670
|
+
/**
|
|
671
|
+
* Used when you want to check that two objects have the same value.
|
|
672
|
+
* This matcher recursively checks the equality of all fields, rather than checking for object identity.
|
|
673
|
+
*
|
|
674
|
+
* @example
|
|
675
|
+
* expect(user).toEqual({ name: 'Alice', age: 30 });
|
|
676
|
+
*/
|
|
677
|
+
toEqual: <E>(expected: E) => void;
|
|
678
|
+
/**
|
|
679
|
+
* Use to test that objects have the same types as well as structure.
|
|
680
|
+
*
|
|
681
|
+
* @example
|
|
682
|
+
* expect(user).toStrictEqual({ name: 'Alice', age: 30 });
|
|
683
|
+
*/
|
|
684
|
+
toStrictEqual: <E>(expected: E) => void;
|
|
685
|
+
/**
|
|
686
|
+
* Checks that a value is what you expect. It calls `Object.is` to compare values.
|
|
687
|
+
* Don't use `toBe` with floating-point numbers.
|
|
688
|
+
*
|
|
689
|
+
* @example
|
|
690
|
+
* expect(result).toBe(42);
|
|
691
|
+
* expect(status).toBe(true);
|
|
692
|
+
*/
|
|
693
|
+
toBe: <E>(expected: E) => void;
|
|
694
|
+
/**
|
|
695
|
+
* Check that a string matches a regular expression.
|
|
696
|
+
*
|
|
697
|
+
* @example
|
|
698
|
+
* expect(message).toMatch(/hello/);
|
|
699
|
+
* expect(greeting).toMatch('world');
|
|
700
|
+
*/
|
|
701
|
+
toMatch: (expected: string | RegExp) => void;
|
|
702
|
+
/**
|
|
703
|
+
* Used to check that a JavaScript object matches a subset of the properties of an object
|
|
704
|
+
*
|
|
705
|
+
* @example
|
|
706
|
+
* expect(user).toMatchObject({
|
|
707
|
+
* name: 'Alice',
|
|
708
|
+
* address: { city: 'Wonderland' }
|
|
709
|
+
* });
|
|
710
|
+
*/
|
|
711
|
+
toMatchObject: <E extends object | any[]>(expected: E) => void;
|
|
712
|
+
/**
|
|
713
|
+
* Used when you want to check that an item is in a list.
|
|
714
|
+
* For testing the items in the list, this uses `===`, a strict equality check.
|
|
715
|
+
*
|
|
716
|
+
* @example
|
|
717
|
+
* expect(items).toContain('apple');
|
|
718
|
+
* expect(numbers).toContain(5);
|
|
719
|
+
*/
|
|
720
|
+
toContain: <E>(item: E) => void;
|
|
721
|
+
/**
|
|
722
|
+
* Used when you want to check that an item is in a list.
|
|
723
|
+
* For testing the items in the list, this matcher recursively checks the
|
|
724
|
+
* equality of all fields, rather than checking for object identity.
|
|
725
|
+
*
|
|
726
|
+
* @example
|
|
727
|
+
* expect(items).toContainEqual({ name: 'apple', quantity: 1 });
|
|
728
|
+
*/
|
|
729
|
+
toContainEqual: <E>(item: E) => void;
|
|
730
|
+
/**
|
|
731
|
+
* Use when you don't care what a value is, you just want to ensure a value
|
|
732
|
+
* is true in a boolean context. In JavaScript, there are six falsy values:
|
|
733
|
+
* `false`, `0`, `''`, `null`, `undefined`, and `NaN`. Everything else is truthy.
|
|
734
|
+
*
|
|
735
|
+
* @example
|
|
736
|
+
* expect(user.isActive).toBeTruthy();
|
|
737
|
+
*/
|
|
738
|
+
toBeTruthy: () => void;
|
|
739
|
+
/**
|
|
740
|
+
* When you don't care what a value is, you just want to
|
|
741
|
+
* ensure a value is false in a boolean context.
|
|
742
|
+
*
|
|
743
|
+
* @example
|
|
744
|
+
* expect(user.isActive).toBeFalsy();
|
|
745
|
+
*/
|
|
746
|
+
toBeFalsy: () => void;
|
|
747
|
+
/**
|
|
748
|
+
* For comparing floating point numbers.
|
|
749
|
+
*
|
|
750
|
+
* @example
|
|
751
|
+
* expect(score).toBeGreaterThan(10);
|
|
752
|
+
*/
|
|
753
|
+
toBeGreaterThan: (num: number | bigint) => void;
|
|
754
|
+
/**
|
|
755
|
+
* For comparing floating point numbers.
|
|
756
|
+
*
|
|
757
|
+
* @example
|
|
758
|
+
* expect(score).toBeGreaterThanOrEqual(10);
|
|
759
|
+
*/
|
|
760
|
+
toBeGreaterThanOrEqual: (num: number | bigint) => void;
|
|
761
|
+
/**
|
|
762
|
+
* For comparing floating point numbers.
|
|
763
|
+
*
|
|
764
|
+
* @example
|
|
765
|
+
* expect(score).toBeLessThan(10);
|
|
766
|
+
*/
|
|
767
|
+
toBeLessThan: (num: number | bigint) => void;
|
|
768
|
+
/**
|
|
769
|
+
* For comparing floating point numbers.
|
|
770
|
+
*
|
|
771
|
+
* @example
|
|
772
|
+
* expect(score).toBeLessThanOrEqual(10);
|
|
773
|
+
*/
|
|
774
|
+
toBeLessThanOrEqual: (num: number | bigint) => void;
|
|
775
|
+
/**
|
|
776
|
+
* Used to check that a variable is NaN.
|
|
777
|
+
*
|
|
778
|
+
* @example
|
|
779
|
+
* expect(value).toBeNaN();
|
|
780
|
+
*/
|
|
781
|
+
toBeNaN: () => void;
|
|
782
|
+
/**
|
|
783
|
+
* Used to check that a variable is undefined.
|
|
784
|
+
*
|
|
785
|
+
* @example
|
|
786
|
+
* expect(value).toBeUndefined();
|
|
787
|
+
*/
|
|
788
|
+
toBeUndefined: () => void;
|
|
789
|
+
/**
|
|
790
|
+
* This is the same as `.toBe(null)` but the error messages are a bit nicer.
|
|
791
|
+
* So use `.toBeNull()` when you want to check that something is null.
|
|
792
|
+
*
|
|
793
|
+
* @example
|
|
794
|
+
* expect(value).toBeNull();
|
|
795
|
+
*/
|
|
796
|
+
toBeNull: () => void;
|
|
797
|
+
/**
|
|
798
|
+
* Ensure that a variable is not undefined.
|
|
799
|
+
*
|
|
800
|
+
* @example
|
|
801
|
+
* expect(value).toBeDefined();
|
|
802
|
+
*/
|
|
803
|
+
toBeDefined: () => void;
|
|
804
|
+
/**
|
|
805
|
+
* Ensure that an object is an instance of a class.
|
|
806
|
+
* This matcher uses `instanceof` underneath.
|
|
807
|
+
*
|
|
808
|
+
* @example
|
|
809
|
+
* expect(new Date()).toBeInstanceOf(Date);
|
|
810
|
+
*/
|
|
811
|
+
toBeInstanceOf: <E>(expected: E) => void;
|
|
812
|
+
/**
|
|
813
|
+
* Used to check that an object has a `.length` property
|
|
814
|
+
* and it is set to a certain numeric value.
|
|
815
|
+
*
|
|
816
|
+
* @example
|
|
817
|
+
* expect([1, 2, 3]).toHaveLength(3);
|
|
818
|
+
* expect('hello').toHaveLength(5);
|
|
819
|
+
*/
|
|
820
|
+
toHaveLength: (length: number) => void;
|
|
821
|
+
/**
|
|
822
|
+
* Use to check if a property at the specified path exists on an object.
|
|
823
|
+
* For checking deeply nested properties, you may use dot notation or an array containing
|
|
824
|
+
* the path segments for deep references.
|
|
825
|
+
*
|
|
826
|
+
* Optionally, you can provide a value to check if it matches the value present at the path
|
|
827
|
+
* on the target object. This matcher uses 'deep equality' (like `toEqual()`) and recursively checks
|
|
828
|
+
* the equality of all fields.
|
|
829
|
+
*
|
|
830
|
+
* @example
|
|
831
|
+
* expect(user).toHaveProperty('address.city', 'New York');
|
|
832
|
+
* expect(config).toHaveProperty(['settings', 'theme'], 'dark');
|
|
833
|
+
*/
|
|
834
|
+
toHaveProperty: <E>(property: string | (string | number)[], value?: E) => void;
|
|
835
|
+
/**
|
|
836
|
+
* Using exact equality with floating point numbers is a bad idea.
|
|
837
|
+
* Rounding means that intuitive things fail.
|
|
838
|
+
* The default for `precision` is 2.
|
|
839
|
+
*
|
|
840
|
+
* @example
|
|
841
|
+
* expect(price).toBeCloseTo(9.99, 2);
|
|
842
|
+
*/
|
|
843
|
+
toBeCloseTo: (number: number, numDigits?: number) => void;
|
|
844
|
+
/**
|
|
845
|
+
* Ensures that a mock function is called an exact number of times.
|
|
846
|
+
*
|
|
847
|
+
* Also under the alias `expect.toBeCalledTimes`.
|
|
848
|
+
*
|
|
849
|
+
* @example
|
|
850
|
+
* expect(mockFunc).toHaveBeenCalledTimes(2);
|
|
851
|
+
*/
|
|
852
|
+
toHaveBeenCalledTimes: (times: number) => void;
|
|
853
|
+
/**
|
|
854
|
+
* Ensures that a mock function is called an exact number of times.
|
|
855
|
+
*
|
|
856
|
+
* Alias for `expect.toHaveBeenCalledTimes`.
|
|
857
|
+
*
|
|
858
|
+
* @example
|
|
859
|
+
* expect(mockFunc).toBeCalledTimes(2);
|
|
860
|
+
*/
|
|
861
|
+
toBeCalledTimes: (times: number) => void;
|
|
862
|
+
/**
|
|
863
|
+
* Ensures that a mock function is called.
|
|
864
|
+
*
|
|
865
|
+
* Also under the alias `expect.toBeCalled`.
|
|
866
|
+
*
|
|
867
|
+
* @example
|
|
868
|
+
* expect(mockFunc).toHaveBeenCalled();
|
|
869
|
+
*/
|
|
870
|
+
toHaveBeenCalled: () => void;
|
|
871
|
+
/**
|
|
872
|
+
* Ensures that a mock function is called.
|
|
873
|
+
*
|
|
874
|
+
* Alias for `expect.toHaveBeenCalled`.
|
|
875
|
+
*
|
|
876
|
+
* @example
|
|
877
|
+
* expect(mockFunc).toBeCalled();
|
|
878
|
+
*/
|
|
879
|
+
toBeCalled: () => void;
|
|
880
|
+
/**
|
|
881
|
+
* Ensure that a mock function is called with specific arguments.
|
|
882
|
+
*
|
|
883
|
+
* Also under the alias `expect.toBeCalledWith`.
|
|
884
|
+
*
|
|
885
|
+
* @example
|
|
886
|
+
* expect(mockFunc).toHaveBeenCalledWith('arg1', 42);
|
|
887
|
+
*/
|
|
888
|
+
toHaveBeenCalledWith: <E extends any[]>(...args: E) => void;
|
|
889
|
+
/**
|
|
890
|
+
* Ensure that a mock function is called with specific arguments.
|
|
891
|
+
*
|
|
892
|
+
* Alias for `expect.toHaveBeenCalledWith`.
|
|
893
|
+
*
|
|
894
|
+
* @example
|
|
895
|
+
* expect(mockFunc).toBeCalledWith('arg1', 42);
|
|
896
|
+
*/
|
|
897
|
+
toBeCalledWith: <E extends any[]>(...args: E) => void;
|
|
898
|
+
/**
|
|
899
|
+
* Ensure that a mock function is called with specific arguments on an Nth call.
|
|
900
|
+
*
|
|
901
|
+
* Also under the alias `expect.nthCalledWith`.
|
|
902
|
+
*
|
|
903
|
+
* @example
|
|
904
|
+
* expect(mockFunc).toHaveBeenNthCalledWith(2, 'secondArg');
|
|
905
|
+
*/
|
|
906
|
+
toHaveBeenNthCalledWith: <E extends any[]>(n: number, ...args: E) => void;
|
|
907
|
+
/**
|
|
908
|
+
* Ensure that a mock function is called with specific arguments on an Nth call.
|
|
909
|
+
*
|
|
910
|
+
* Alias for `expect.toHaveBeenNthCalledWith`.
|
|
911
|
+
*
|
|
912
|
+
* @example
|
|
913
|
+
* expect(mockFunc).nthCalledWith(2, 'secondArg');
|
|
914
|
+
*/
|
|
915
|
+
nthCalledWith: <E extends any[]>(nthCall: number, ...args: E) => void;
|
|
916
|
+
/**
|
|
917
|
+
* If you have a mock function, you can use `.toHaveBeenLastCalledWith`
|
|
918
|
+
* to test what arguments it was last called with.
|
|
919
|
+
*
|
|
920
|
+
* Also under the alias `expect.lastCalledWith`.
|
|
921
|
+
*
|
|
922
|
+
* @example
|
|
923
|
+
* expect(mockFunc).toHaveBeenLastCalledWith('lastArg');
|
|
924
|
+
*/
|
|
925
|
+
toHaveBeenLastCalledWith: <E extends any[]>(...args: E) => void;
|
|
926
|
+
/**
|
|
927
|
+
* If you have a mock function, you can use `.lastCalledWith`
|
|
928
|
+
* to test what arguments it was last called with.
|
|
929
|
+
*
|
|
930
|
+
* Alias for `expect.toHaveBeenLastCalledWith`.
|
|
931
|
+
*
|
|
932
|
+
* @example
|
|
933
|
+
* expect(mockFunc).lastCalledWith('lastArg');
|
|
934
|
+
*/
|
|
935
|
+
lastCalledWith: <E extends any[]>(...args: E) => void;
|
|
936
|
+
/**
|
|
937
|
+
* Used to test that a function throws when it is called.
|
|
938
|
+
*
|
|
939
|
+
* Also under the alias `expect.toThrowError`.
|
|
940
|
+
*
|
|
941
|
+
* @example
|
|
942
|
+
* expect(() => functionWithError()).toThrow('Error message');
|
|
943
|
+
* expect(() => parseJSON('invalid')).toThrow(SyntaxError);
|
|
944
|
+
*/
|
|
945
|
+
toThrow: (expected?: string | Constructable | RegExp | Error) => void;
|
|
946
|
+
/**
|
|
947
|
+
* Used to test that a function throws when it is called.
|
|
948
|
+
*
|
|
949
|
+
* Alias for `expect.toThrow`.
|
|
950
|
+
*
|
|
951
|
+
* @example
|
|
952
|
+
* expect(() => functionWithError()).toThrowError('Error message');
|
|
953
|
+
* expect(() => parseJSON('invalid')).toThrowError(SyntaxError);
|
|
954
|
+
*/
|
|
955
|
+
toThrowError: (expected?: string | Constructable | RegExp | Error) => void;
|
|
956
|
+
/**
|
|
957
|
+
* Use to test that the mock function successfully returned (i.e., did not throw an error) at least one time
|
|
958
|
+
*
|
|
959
|
+
* Alias for `expect.toHaveReturned`.
|
|
960
|
+
*
|
|
961
|
+
* @example
|
|
962
|
+
* expect(mockFunc).toReturn();
|
|
963
|
+
*/
|
|
964
|
+
toReturn: () => void;
|
|
965
|
+
/**
|
|
966
|
+
* Use to test that the mock function successfully returned (i.e., did not throw an error) at least one time
|
|
967
|
+
*
|
|
968
|
+
* Also under the alias `expect.toReturn`.
|
|
969
|
+
*
|
|
970
|
+
* @example
|
|
971
|
+
* expect(mockFunc).toHaveReturned();
|
|
972
|
+
*/
|
|
973
|
+
toHaveReturned: () => void;
|
|
974
|
+
/**
|
|
975
|
+
* Use to ensure that a mock function returned successfully (i.e., did not throw an error) an exact number of times.
|
|
976
|
+
* Any calls to the mock function that throw an error are not counted toward the number of times the function returned.
|
|
977
|
+
*
|
|
978
|
+
* Alias for `expect.toHaveReturnedTimes`.
|
|
979
|
+
*
|
|
980
|
+
* @example
|
|
981
|
+
* expect(mockFunc).toReturnTimes(3);
|
|
982
|
+
*/
|
|
983
|
+
toReturnTimes: (times: number) => void;
|
|
984
|
+
/**
|
|
985
|
+
* Use to ensure that a mock function returned successfully (i.e., did not throw an error) an exact number of times.
|
|
986
|
+
* Any calls to the mock function that throw an error are not counted toward the number of times the function returned.
|
|
987
|
+
*
|
|
988
|
+
* Also under the alias `expect.toReturnTimes`.
|
|
989
|
+
*
|
|
990
|
+
* @example
|
|
991
|
+
* expect(mockFunc).toHaveReturnedTimes(3);
|
|
992
|
+
*/
|
|
993
|
+
toHaveReturnedTimes: (times: number) => void;
|
|
994
|
+
/**
|
|
995
|
+
* Use to ensure that a mock function returned a specific value.
|
|
996
|
+
*
|
|
997
|
+
* Alias for `expect.toHaveReturnedWith`.
|
|
998
|
+
*
|
|
999
|
+
* @example
|
|
1000
|
+
* expect(mockFunc).toReturnWith('returnValue');
|
|
1001
|
+
*/
|
|
1002
|
+
toReturnWith: <E>(value: E) => void;
|
|
1003
|
+
/**
|
|
1004
|
+
* Use to ensure that a mock function returned a specific value.
|
|
1005
|
+
*
|
|
1006
|
+
* Also under the alias `expect.toReturnWith`.
|
|
1007
|
+
*
|
|
1008
|
+
* @example
|
|
1009
|
+
* expect(mockFunc).toHaveReturnedWith('returnValue');
|
|
1010
|
+
*/
|
|
1011
|
+
toHaveReturnedWith: <E>(value: E) => void;
|
|
1012
|
+
/**
|
|
1013
|
+
* Use to test the specific value that a mock function last returned.
|
|
1014
|
+
* If the last call to the mock function threw an error, then this matcher will fail
|
|
1015
|
+
* no matter what value you provided as the expected return value.
|
|
1016
|
+
*
|
|
1017
|
+
* Also under the alias `expect.lastReturnedWith`.
|
|
1018
|
+
*
|
|
1019
|
+
* @example
|
|
1020
|
+
* expect(mockFunc).toHaveLastReturnedWith('lastValue');
|
|
1021
|
+
*/
|
|
1022
|
+
toHaveLastReturnedWith: <E>(value: E) => void;
|
|
1023
|
+
/**
|
|
1024
|
+
* Use to test the specific value that a mock function last returned.
|
|
1025
|
+
* If the last call to the mock function threw an error, then this matcher will fail
|
|
1026
|
+
* no matter what value you provided as the expected return value.
|
|
1027
|
+
*
|
|
1028
|
+
* Alias for `expect.toHaveLastReturnedWith`.
|
|
1029
|
+
*
|
|
1030
|
+
* @example
|
|
1031
|
+
* expect(mockFunc).lastReturnedWith('lastValue');
|
|
1032
|
+
*/
|
|
1033
|
+
lastReturnedWith: <E>(value: E) => void;
|
|
1034
|
+
/**
|
|
1035
|
+
* Use to test the specific value that a mock function returned for the nth call.
|
|
1036
|
+
* If the nth call to the mock function threw an error, then this matcher will fail
|
|
1037
|
+
* no matter what value you provided as the expected return value.
|
|
1038
|
+
*
|
|
1039
|
+
* Also under the alias `expect.nthReturnedWith`.
|
|
1040
|
+
*
|
|
1041
|
+
* @example
|
|
1042
|
+
* expect(mockFunc).toHaveNthReturnedWith(2, 'nthValue');
|
|
1043
|
+
*/
|
|
1044
|
+
toHaveNthReturnedWith: <E>(nthCall: number, value: E) => void;
|
|
1045
|
+
/**
|
|
1046
|
+
* Use to test the specific value that a mock function returned for the nth call.
|
|
1047
|
+
* If the nth call to the mock function threw an error, then this matcher will fail
|
|
1048
|
+
* no matter what value you provided as the expected return value.
|
|
1049
|
+
*
|
|
1050
|
+
* Alias for `expect.toHaveNthReturnedWith`.
|
|
1051
|
+
*
|
|
1052
|
+
* @example
|
|
1053
|
+
* expect(mockFunc).nthReturnedWith(2, 'nthValue');
|
|
1054
|
+
*/
|
|
1055
|
+
nthReturnedWith: <E>(nthCall: number, value: E) => void;
|
|
1056
|
+
}
|
|
1057
|
+
|
|
1058
|
+
declare function matcherHint(matcherName: string, received?: string, expected?: string, options?: MatcherHintOptions): string;
|
|
1059
|
+
|
|
1060
|
+
declare interface MatcherHintOptions {
|
|
1061
|
+
comment?: string;
|
|
1062
|
+
expectedColor?: Formatter;
|
|
1063
|
+
isDirectExpectCall?: boolean;
|
|
1064
|
+
isNot?: boolean;
|
|
1065
|
+
promise?: string;
|
|
1066
|
+
receivedColor?: Formatter;
|
|
1067
|
+
secondArgument?: string;
|
|
1068
|
+
secondArgumentColor?: Formatter;
|
|
1069
|
+
}
|
|
1070
|
+
|
|
1071
|
+
declare interface Matchers<T = any> {}
|
|
1072
|
+
|
|
1073
|
+
declare type MatchersObject<T extends MatcherState = MatcherState> = Record<string, RawMatcherFn<T>> & ThisType<T> & { [K in keyof Matchers<T>]? : RawMatcherFn<T, Parameters<Matchers<T>[K]>> };
|
|
1074
|
+
|
|
1075
|
+
declare interface MatcherState {
|
|
1076
|
+
customTesters: Array<Tester>;
|
|
1077
|
+
assertionCalls: number;
|
|
1078
|
+
currentTestName?: string;
|
|
1079
|
+
dontThrow?: () => void;
|
|
1080
|
+
error?: Error;
|
|
1081
|
+
equals: (a: unknown, b: unknown, customTesters?: Array<Tester>, strictCheck?: boolean) => boolean;
|
|
1082
|
+
expand?: boolean;
|
|
1083
|
+
expectedAssertionsNumber?: number | null;
|
|
1084
|
+
expectedAssertionsNumberErrorGen?: (() => Error) | null;
|
|
1085
|
+
isExpectingAssertions?: boolean;
|
|
1086
|
+
isExpectingAssertionsError?: Error | null;
|
|
1087
|
+
isNot: boolean;
|
|
1088
|
+
// environment: VitestEnvironment
|
|
1089
|
+
promise: string;
|
|
1090
|
+
// snapshotState: SnapshotState
|
|
1091
|
+
suppressedErrors: Array<Error>;
|
|
1092
|
+
testPath?: string;
|
|
1093
|
+
utils: ReturnType<typeof getMatcherUtils> & {
|
|
1094
|
+
diff: typeof diff
|
|
1095
|
+
stringify: typeof stringify
|
|
1096
|
+
iterableEquality: Tester
|
|
1097
|
+
subsetEquality: Tester
|
|
1098
|
+
};
|
|
1099
|
+
soft?: boolean;
|
|
1100
|
+
poll?: boolean;
|
|
1101
|
+
}
|
|
1102
|
+
|
|
1103
|
+
declare interface MatcherState_2 extends MatcherState {
|
|
314
1104
|
environment: string;
|
|
315
1105
|
snapshotState: SnapshotState;
|
|
316
1106
|
}
|
|
317
1107
|
|
|
318
1108
|
declare type MaybePromise<T> = T | Promise<T>;
|
|
319
1109
|
|
|
320
|
-
export declare interface Mock<T extends FunctionLike = FunctionLike> extends
|
|
1110
|
+
export declare interface Mock<T extends FunctionLike = FunctionLike> extends MockInstance_2<T> {
|
|
321
1111
|
new (...args: Parameters<T>): ReturnType<T>;
|
|
322
1112
|
(...args: Parameters<T>): ReturnType<T>;
|
|
323
1113
|
}
|
|
324
1114
|
|
|
325
|
-
declare
|
|
1115
|
+
declare interface MockContext<T extends Procedure> {
|
|
1116
|
+
/**
|
|
1117
|
+
* This is an array containing all arguments for each call. One item of the array is the arguments of that call.
|
|
1118
|
+
*
|
|
1119
|
+
* @see https://vitest.dev/api/mock#mock-calls
|
|
1120
|
+
* @example
|
|
1121
|
+
* const fn = vi.fn()
|
|
1122
|
+
*
|
|
1123
|
+
* fn('arg1', 'arg2')
|
|
1124
|
+
* fn('arg3')
|
|
1125
|
+
*
|
|
1126
|
+
* fn.mock.calls === [
|
|
1127
|
+
* ['arg1', 'arg2'], // first call
|
|
1128
|
+
* ['arg3'], // second call
|
|
1129
|
+
* ]
|
|
1130
|
+
*/
|
|
1131
|
+
calls: Parameters<T>[];
|
|
1132
|
+
/**
|
|
1133
|
+
* 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.
|
|
1134
|
+
* @see https://vitest.dev/api/mock#mock-instances
|
|
1135
|
+
*/
|
|
1136
|
+
instances: ReturnType<T>[];
|
|
1137
|
+
/**
|
|
1138
|
+
* An array of `this` values that were used during each call to the mock function.
|
|
1139
|
+
* @see https://vitest.dev/api/mock#mock-contexts
|
|
1140
|
+
*/
|
|
1141
|
+
contexts: ThisParameterType<T>[];
|
|
1142
|
+
/**
|
|
1143
|
+
* The order of mock's execution. This returns an array of numbers which are shared between all defined mocks.
|
|
1144
|
+
*
|
|
1145
|
+
* @see https://vitest.dev/api/mock#mock-invocationcallorder
|
|
1146
|
+
* @example
|
|
1147
|
+
* const fn1 = vi.fn()
|
|
1148
|
+
* const fn2 = vi.fn()
|
|
1149
|
+
*
|
|
1150
|
+
* fn1()
|
|
1151
|
+
* fn2()
|
|
1152
|
+
* fn1()
|
|
1153
|
+
*
|
|
1154
|
+
* fn1.mock.invocationCallOrder === [1, 3]
|
|
1155
|
+
* fn2.mock.invocationCallOrder === [2]
|
|
1156
|
+
*/
|
|
1157
|
+
invocationCallOrder: number[];
|
|
1158
|
+
/**
|
|
1159
|
+
* This is an array containing all values that were `returned` from the function.
|
|
1160
|
+
*
|
|
1161
|
+
* 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.
|
|
1162
|
+
*
|
|
1163
|
+
* @see https://vitest.dev/api/mock#mock-results
|
|
1164
|
+
* @example
|
|
1165
|
+
* const fn = vi.fn()
|
|
1166
|
+
* .mockReturnValueOnce('result')
|
|
1167
|
+
* .mockImplementationOnce(() => { throw new Error('thrown error') })
|
|
1168
|
+
*
|
|
1169
|
+
* const result = fn()
|
|
1170
|
+
*
|
|
1171
|
+
* try {
|
|
1172
|
+
* fn()
|
|
1173
|
+
* }
|
|
1174
|
+
* catch {}
|
|
1175
|
+
*
|
|
1176
|
+
* fn.mock.results === [
|
|
1177
|
+
* {
|
|
1178
|
+
* type: 'return',
|
|
1179
|
+
* value: 'result',
|
|
1180
|
+
* },
|
|
1181
|
+
* {
|
|
1182
|
+
* type: 'throw',
|
|
1183
|
+
* value: Error,
|
|
1184
|
+
* },
|
|
1185
|
+
* ]
|
|
1186
|
+
*/
|
|
1187
|
+
results: MockResult<ReturnType<T>>[];
|
|
1188
|
+
/**
|
|
1189
|
+
* An array containing all values that were `resolved` or `rejected` from the function.
|
|
1190
|
+
*
|
|
1191
|
+
* This array will be empty if the function was never resolved or rejected.
|
|
1192
|
+
*
|
|
1193
|
+
* @see https://vitest.dev/api/mock#mock-settledresults
|
|
1194
|
+
* @example
|
|
1195
|
+
* const fn = vi.fn().mockResolvedValueOnce('result')
|
|
1196
|
+
*
|
|
1197
|
+
* const result = fn()
|
|
1198
|
+
*
|
|
1199
|
+
* fn.mock.settledResults === []
|
|
1200
|
+
* fn.mock.results === [
|
|
1201
|
+
* {
|
|
1202
|
+
* type: 'return',
|
|
1203
|
+
* value: Promise<'result'>,
|
|
1204
|
+
* },
|
|
1205
|
+
* ]
|
|
1206
|
+
*
|
|
1207
|
+
* await result
|
|
1208
|
+
*
|
|
1209
|
+
* fn.mock.settledResults === [
|
|
1210
|
+
* {
|
|
1211
|
+
* type: 'fulfilled',
|
|
1212
|
+
* value: 'result',
|
|
1213
|
+
* },
|
|
1214
|
+
* ]
|
|
1215
|
+
*/
|
|
1216
|
+
settledResults: MockSettledResult<Awaited<ReturnType<T>>>[];
|
|
1217
|
+
/**
|
|
1218
|
+
* This contains the arguments of the last call. If spy wasn't called, will return `undefined`.
|
|
1219
|
+
* @see https://vitest.dev/api/mock#mock-lastcall
|
|
1220
|
+
*/
|
|
1221
|
+
lastCall: Parameters<T> | undefined;
|
|
1222
|
+
}
|
|
1223
|
+
|
|
1224
|
+
declare type MockContext_2<T extends FunctionLike = FunctionLike> = {
|
|
326
1225
|
/**
|
|
327
1226
|
* List of the call arguments of all calls that have been made to the mock.
|
|
328
1227
|
*/
|
|
@@ -349,18 +1248,171 @@ declare type MockContext<T extends FunctionLike = FunctionLike> = {
|
|
|
349
1248
|
/**
|
|
350
1249
|
* List of the results of all calls that have been made to the mock.
|
|
351
1250
|
*/
|
|
352
|
-
results: Array<
|
|
1251
|
+
results: Array<MockResult_2<ReturnType<T>>>;
|
|
353
1252
|
/**
|
|
354
1253
|
* List of the results of all values that were `resolved` or `rejected` from the function.
|
|
355
1254
|
*/
|
|
356
|
-
settledResults:
|
|
1255
|
+
settledResults: MockSettledResult_2<Awaited<ReturnType<T>>>[];
|
|
357
1256
|
};
|
|
358
1257
|
|
|
359
1258
|
declare type MockFactory<T = unknown> = () => MaybePromise<Partial<T>>;
|
|
360
1259
|
|
|
361
1260
|
declare type MockFn = <T extends FunctionLike = FunctionLike>(fn?: T) => Mock<T>;
|
|
362
1261
|
|
|
363
|
-
declare interface MockInstance<T extends
|
|
1262
|
+
declare interface MockInstance<T extends Procedure = Procedure> extends Disposable {
|
|
1263
|
+
/**
|
|
1264
|
+
* Use it to return the name assigned to the mock with the `.mockName(name)` method. By default, it will return `vi.fn()`.
|
|
1265
|
+
* @see https://vitest.dev/api/mock#getmockname
|
|
1266
|
+
*/
|
|
1267
|
+
getMockName(): string;
|
|
1268
|
+
/**
|
|
1269
|
+
* Sets the internal mock name. This is useful for identifying the mock when an assertion fails.
|
|
1270
|
+
* @see https://vitest.dev/api/mock#mockname
|
|
1271
|
+
*/
|
|
1272
|
+
mockName(name: string): this;
|
|
1273
|
+
/**
|
|
1274
|
+
* Current context of the mock. It stores information about all invocation calls, instances, and results.
|
|
1275
|
+
*/
|
|
1276
|
+
mock: MockContext<T>;
|
|
1277
|
+
/**
|
|
1278
|
+
* 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.
|
|
1279
|
+
*
|
|
1280
|
+
* To automatically call this method before each test, enable the [`clearMocks`](https://vitest.dev/config/#clearmocks) setting in the configuration.
|
|
1281
|
+
* @see https://vitest.dev/api/mock#mockclear
|
|
1282
|
+
*/
|
|
1283
|
+
mockClear(): this;
|
|
1284
|
+
/**
|
|
1285
|
+
* Does what `mockClear` does and resets inner implementation to the original function. This also resets all "once" implementations.
|
|
1286
|
+
*
|
|
1287
|
+
* Note that resetting a mock from `vi.fn()` will set implementation to an empty function that returns `undefined`.
|
|
1288
|
+
* Resetting a mock from `vi.fn(impl)` will set implementation to `impl`. It is useful for completely resetting a mock to its default state.
|
|
1289
|
+
*
|
|
1290
|
+
* To automatically call this method before each test, enable the [`mockReset`](https://vitest.dev/config/#mockreset) setting in the configuration.
|
|
1291
|
+
* @see https://vitest.dev/api/mock#mockreset
|
|
1292
|
+
*/
|
|
1293
|
+
mockReset(): this;
|
|
1294
|
+
/**
|
|
1295
|
+
* Does what `mockReset` does and restores original descriptors of spied-on objects.
|
|
1296
|
+
*
|
|
1297
|
+
* 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`.
|
|
1298
|
+
* @see https://vitest.dev/api/mock#mockrestore
|
|
1299
|
+
*/
|
|
1300
|
+
mockRestore(): void;
|
|
1301
|
+
/**
|
|
1302
|
+
* Returns current permanent mock implementation if there is one.
|
|
1303
|
+
*
|
|
1304
|
+
* If mock was created with `vi.fn`, it will consider passed down method as a mock implementation.
|
|
1305
|
+
*
|
|
1306
|
+
* If mock was created with `vi.spyOn`, it will return `undefined` unless a custom implementation was provided.
|
|
1307
|
+
*/
|
|
1308
|
+
getMockImplementation(): NormalizedProcedure<T> | undefined;
|
|
1309
|
+
/**
|
|
1310
|
+
* Accepts a function to be used as the mock implementation. TypeScript expects the arguments and return type to match those of the original function.
|
|
1311
|
+
* @see https://vitest.dev/api/mock#mockimplementation
|
|
1312
|
+
* @example
|
|
1313
|
+
* const increment = vi.fn().mockImplementation(count => count + 1);
|
|
1314
|
+
* expect(increment(3)).toBe(4);
|
|
1315
|
+
*/
|
|
1316
|
+
mockImplementation(fn: NormalizedProcedure<T>): this;
|
|
1317
|
+
/**
|
|
1318
|
+
* 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.
|
|
1319
|
+
*
|
|
1320
|
+
* 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.
|
|
1321
|
+
* @see https://vitest.dev/api/mock#mockimplementationonce
|
|
1322
|
+
* @example
|
|
1323
|
+
* const fn = vi.fn(count => count).mockImplementationOnce(count => count + 1);
|
|
1324
|
+
* expect(fn(3)).toBe(4);
|
|
1325
|
+
* expect(fn(3)).toBe(3);
|
|
1326
|
+
*/
|
|
1327
|
+
mockImplementationOnce(fn: NormalizedProcedure<T>): this;
|
|
1328
|
+
/**
|
|
1329
|
+
* Overrides the original mock implementation temporarily while the callback is being executed.
|
|
1330
|
+
*
|
|
1331
|
+
* Note that this method takes precedence over the [`mockImplementationOnce`](https://vitest.dev/api/mock#mockimplementationonce).
|
|
1332
|
+
* @see https://vitest.dev/api/mock#withimplementation
|
|
1333
|
+
* @example
|
|
1334
|
+
* const myMockFn = vi.fn(() => 'original')
|
|
1335
|
+
*
|
|
1336
|
+
* myMockFn.withImplementation(() => 'temp', () => {
|
|
1337
|
+
* myMockFn() // 'temp'
|
|
1338
|
+
* })
|
|
1339
|
+
*
|
|
1340
|
+
* myMockFn() // 'original'
|
|
1341
|
+
*/
|
|
1342
|
+
withImplementation<T2>(fn: NormalizedProcedure<T>, cb: () => T2): T2 extends Promise<unknown> ? Promise<this> : this;
|
|
1343
|
+
/**
|
|
1344
|
+
* Use this if you need to return the `this` context from the method without invoking the actual implementation.
|
|
1345
|
+
* @see https://vitest.dev/api/mock#mockreturnthis
|
|
1346
|
+
*/
|
|
1347
|
+
mockReturnThis(): this;
|
|
1348
|
+
/**
|
|
1349
|
+
* 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.
|
|
1350
|
+
* @see https://vitest.dev/api/mock#mockreturnvalue
|
|
1351
|
+
* @example
|
|
1352
|
+
* const mock = vi.fn()
|
|
1353
|
+
* mock.mockReturnValue(42)
|
|
1354
|
+
* mock() // 42
|
|
1355
|
+
* mock.mockReturnValue(43)
|
|
1356
|
+
* mock() // 43
|
|
1357
|
+
*/
|
|
1358
|
+
mockReturnValue(value: ReturnType<T>): this;
|
|
1359
|
+
/**
|
|
1360
|
+
* 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.
|
|
1361
|
+
*
|
|
1362
|
+
* 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.
|
|
1363
|
+
* @example
|
|
1364
|
+
* const myMockFn = vi
|
|
1365
|
+
* .fn()
|
|
1366
|
+
* .mockReturnValue('default')
|
|
1367
|
+
* .mockReturnValueOnce('first call')
|
|
1368
|
+
* .mockReturnValueOnce('second call')
|
|
1369
|
+
*
|
|
1370
|
+
* // 'first call', 'second call', 'default'
|
|
1371
|
+
* console.log(myMockFn(), myMockFn(), myMockFn())
|
|
1372
|
+
*/
|
|
1373
|
+
mockReturnValueOnce(value: ReturnType<T>): this;
|
|
1374
|
+
/**
|
|
1375
|
+
* 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.
|
|
1376
|
+
* @example
|
|
1377
|
+
* const asyncMock = vi.fn().mockResolvedValue(42)
|
|
1378
|
+
* asyncMock() // Promise<42>
|
|
1379
|
+
*/
|
|
1380
|
+
mockResolvedValue(value: Awaited<ReturnType<T>>): this;
|
|
1381
|
+
/**
|
|
1382
|
+
* 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.
|
|
1383
|
+
* @example
|
|
1384
|
+
* const myMockFn = vi
|
|
1385
|
+
* .fn()
|
|
1386
|
+
* .mockResolvedValue('default')
|
|
1387
|
+
* .mockResolvedValueOnce('first call')
|
|
1388
|
+
* .mockResolvedValueOnce('second call')
|
|
1389
|
+
*
|
|
1390
|
+
* // Promise<'first call'>, Promise<'second call'>, Promise<'default'>
|
|
1391
|
+
* console.log(myMockFn(), myMockFn(), myMockFn())
|
|
1392
|
+
*/
|
|
1393
|
+
mockResolvedValueOnce(value: Awaited<ReturnType<T>>): this;
|
|
1394
|
+
/**
|
|
1395
|
+
* Accepts an error that will be rejected when async function is called.
|
|
1396
|
+
* @example
|
|
1397
|
+
* const asyncMock = vi.fn().mockRejectedValue(new Error('Async error'))
|
|
1398
|
+
* await asyncMock() // throws Error<'Async error'>
|
|
1399
|
+
*/
|
|
1400
|
+
mockRejectedValue(error: unknown): this;
|
|
1401
|
+
/**
|
|
1402
|
+
* Accepts a value that will be rejected during the next function call. If chained, each consecutive call will reject the specified value.
|
|
1403
|
+
* @example
|
|
1404
|
+
* const asyncMock = vi
|
|
1405
|
+
* .fn()
|
|
1406
|
+
* .mockResolvedValueOnce('first call')
|
|
1407
|
+
* .mockRejectedValueOnce(new Error('Async error'))
|
|
1408
|
+
*
|
|
1409
|
+
* await asyncMock() // first call
|
|
1410
|
+
* await asyncMock() // throws Error<'Async error'>
|
|
1411
|
+
*/
|
|
1412
|
+
mockRejectedValueOnce(error: unknown): this;
|
|
1413
|
+
}
|
|
1414
|
+
|
|
1415
|
+
declare interface MockInstance_2<T extends FunctionLike = FunctionLike> {
|
|
364
1416
|
_isMockFunction: true;
|
|
365
1417
|
/**
|
|
366
1418
|
* Returns the mock name string set by calling `.mockName()`
|
|
@@ -370,7 +1422,7 @@ declare interface MockInstance<T extends FunctionLike = FunctionLike> {
|
|
|
370
1422
|
* Sets the mock name for this mock.
|
|
371
1423
|
*/
|
|
372
1424
|
mockName(name: string): this;
|
|
373
|
-
mock:
|
|
1425
|
+
mock: MockContext_2<T>;
|
|
374
1426
|
/**
|
|
375
1427
|
* Clears all information about every call.
|
|
376
1428
|
*/
|
|
@@ -386,19 +1438,19 @@ declare interface MockInstance<T extends FunctionLike = FunctionLike> {
|
|
|
386
1438
|
/**
|
|
387
1439
|
* Returns current mock implementation if there is one.
|
|
388
1440
|
*/
|
|
389
|
-
getMockImplementation():
|
|
1441
|
+
getMockImplementation(): NormalizedProcedure_2<T> | undefined;
|
|
390
1442
|
/**
|
|
391
1443
|
* Accepts a function that should be used as the implementation of the mock.
|
|
392
1444
|
*/
|
|
393
|
-
mockImplementation(fn:
|
|
1445
|
+
mockImplementation(fn: NormalizedProcedure_2<T>): this;
|
|
394
1446
|
/**
|
|
395
1447
|
* Accepts a function that will be used as an implementation of the mock for one call to the mocked function.
|
|
396
1448
|
*/
|
|
397
|
-
mockImplementationOnce(fn:
|
|
1449
|
+
mockImplementationOnce(fn: NormalizedProcedure_2<T>): this;
|
|
398
1450
|
/**
|
|
399
1451
|
* Accepts a function which should be temporarily used as the implementation of the mock while the callback is being executed.
|
|
400
1452
|
*/
|
|
401
|
-
withImplementation<T2>(fn:
|
|
1453
|
+
withImplementation<T2>(fn: NormalizedProcedure_2<T>, callback: () => T2): T2 extends Promise<unknown> ? Promise<void> : void;
|
|
402
1454
|
/**
|
|
403
1455
|
* Return the `this` context from the method without invoking the actual implementation.
|
|
404
1456
|
*/
|
|
@@ -431,12 +1483,27 @@ declare interface MockInstance<T extends FunctionLike = FunctionLike> {
|
|
|
431
1483
|
|
|
432
1484
|
declare type MockResult<T> = MockResultReturn<T> | MockResultThrow | MockResultIncomplete;
|
|
433
1485
|
|
|
1486
|
+
declare type MockResult_2<T> = MockResultReturn_2<T> | MockResultThrow_2 | MockResultIncomplete_2;
|
|
1487
|
+
|
|
434
1488
|
declare interface MockResultIncomplete {
|
|
1489
|
+
type: "incomplete";
|
|
1490
|
+
value: undefined;
|
|
1491
|
+
}
|
|
1492
|
+
|
|
1493
|
+
declare interface MockResultIncomplete_2 {
|
|
435
1494
|
type: 'incomplete';
|
|
436
1495
|
value: undefined;
|
|
437
1496
|
}
|
|
438
1497
|
|
|
439
1498
|
declare interface MockResultReturn<T> {
|
|
1499
|
+
type: "return";
|
|
1500
|
+
/**
|
|
1501
|
+
* The value that was returned from the function. If function returned a Promise, then this will be a resolved value.
|
|
1502
|
+
*/
|
|
1503
|
+
value: T;
|
|
1504
|
+
}
|
|
1505
|
+
|
|
1506
|
+
declare interface MockResultReturn_2<T> {
|
|
440
1507
|
type: 'return';
|
|
441
1508
|
/**
|
|
442
1509
|
* The value that was returned from the function. If function returned a Promise, then this will be a resolved value.
|
|
@@ -445,6 +1512,14 @@ declare interface MockResultReturn<T> {
|
|
|
445
1512
|
}
|
|
446
1513
|
|
|
447
1514
|
declare interface MockResultThrow {
|
|
1515
|
+
type: "throw";
|
|
1516
|
+
/**
|
|
1517
|
+
* An error that was thrown during function execution.
|
|
1518
|
+
*/
|
|
1519
|
+
value: any;
|
|
1520
|
+
}
|
|
1521
|
+
|
|
1522
|
+
declare interface MockResultThrow_2 {
|
|
448
1523
|
type: 'throw';
|
|
449
1524
|
/**
|
|
450
1525
|
* An error that was thrown during function execution.
|
|
@@ -454,18 +1529,35 @@ declare interface MockResultThrow {
|
|
|
454
1529
|
|
|
455
1530
|
declare type MockSettledResult<T> = MockSettledResultFulfilled<T> | MockSettledResultRejected;
|
|
456
1531
|
|
|
1532
|
+
declare type MockSettledResult_2<T> = MockSettledResultFulfilled_2<T> | MockSettledResultRejected_2;
|
|
1533
|
+
|
|
457
1534
|
declare interface MockSettledResultFulfilled<T> {
|
|
1535
|
+
type: "fulfilled";
|
|
1536
|
+
value: T;
|
|
1537
|
+
}
|
|
1538
|
+
|
|
1539
|
+
declare interface MockSettledResultFulfilled_2<T> {
|
|
458
1540
|
type: 'fulfilled';
|
|
459
1541
|
value: T;
|
|
460
1542
|
}
|
|
461
1543
|
|
|
462
1544
|
declare interface MockSettledResultRejected {
|
|
1545
|
+
type: "rejected";
|
|
1546
|
+
value: any;
|
|
1547
|
+
}
|
|
1548
|
+
|
|
1549
|
+
declare interface MockSettledResultRejected_2 {
|
|
463
1550
|
type: 'rejected';
|
|
464
1551
|
value: any;
|
|
465
1552
|
}
|
|
466
1553
|
|
|
467
1554
|
declare type NamesIndex = number;
|
|
468
1555
|
|
|
1556
|
+
declare interface NewPlugin {
|
|
1557
|
+
serialize: (val: any, config: Config, indentation: string, depth: number, refs: Refs, printer: Printer) => string;
|
|
1558
|
+
test: Test;
|
|
1559
|
+
}
|
|
1560
|
+
|
|
469
1561
|
declare type NormalizedConfig = Required<Omit<RstestConfig, OptionalKeys | 'pool'>> & {
|
|
470
1562
|
[key in OptionalKeys]?: RstestConfig[key];
|
|
471
1563
|
} & {
|
|
@@ -474,15 +1566,89 @@ declare type NormalizedConfig = Required<Omit<RstestConfig, OptionalKeys | 'pool
|
|
|
474
1566
|
|
|
475
1567
|
declare type NormalizedProcedure<T extends Procedure> = (...args: Parameters<T>) => ReturnType<T>;
|
|
476
1568
|
|
|
1569
|
+
declare type NormalizedProcedure_2<T extends Procedure_2> = (...args: Parameters<T>) => ReturnType<T>;
|
|
1570
|
+
|
|
1571
|
+
declare interface OldPlugin {
|
|
1572
|
+
print: (val: unknown, print: Print, indent: Indent, options: PluginOptions, colors: Colors) => string;
|
|
1573
|
+
test: Test;
|
|
1574
|
+
}
|
|
1575
|
+
|
|
477
1576
|
declare type OptionalKeys = 'setupFiles' | 'testNamePattern' | 'plugins' | 'source' | 'resolve' | 'output' | 'performance' | 'tools' | 'dev' | 'onConsoleLog';
|
|
478
1577
|
|
|
1578
|
+
declare type OptionsReceived = PrettyFormatOptions;
|
|
1579
|
+
|
|
1580
|
+
declare interface ParsedStack {
|
|
1581
|
+
method: string;
|
|
1582
|
+
file: string;
|
|
1583
|
+
line: number;
|
|
1584
|
+
column: number;
|
|
1585
|
+
}
|
|
1586
|
+
|
|
1587
|
+
declare type Plugin_2 = NewPlugin | OldPlugin;
|
|
1588
|
+
|
|
1589
|
+
declare interface PluginOptions {
|
|
1590
|
+
edgeSpacing: string;
|
|
1591
|
+
min: boolean;
|
|
1592
|
+
spacing: string;
|
|
1593
|
+
}
|
|
1594
|
+
|
|
1595
|
+
declare type Plugins = Array<Plugin_2>;
|
|
1596
|
+
|
|
1597
|
+
declare interface PrettyFormatOptions {
|
|
1598
|
+
callToJSON?: boolean;
|
|
1599
|
+
escapeRegex?: boolean;
|
|
1600
|
+
escapeString?: boolean;
|
|
1601
|
+
highlight?: boolean;
|
|
1602
|
+
indent?: number;
|
|
1603
|
+
maxDepth?: number;
|
|
1604
|
+
maxWidth?: number;
|
|
1605
|
+
min?: boolean;
|
|
1606
|
+
printBasicPrototype?: boolean;
|
|
1607
|
+
printFunctionName?: boolean;
|
|
1608
|
+
compareKeys?: CompareKeys;
|
|
1609
|
+
plugins?: Plugins;
|
|
1610
|
+
}
|
|
1611
|
+
|
|
1612
|
+
declare type Print = (arg0: unknown) => string;
|
|
1613
|
+
|
|
1614
|
+
declare function printDiffOrStringify(received: unknown, expected: unknown, options?: DiffOptions): string | undefined;
|
|
1615
|
+
|
|
1616
|
+
declare type Printer = (val: unknown, config: Config, indentation: string, depth: number, refs: Refs, hasCalledToJSON?: boolean) => string;
|
|
1617
|
+
|
|
1618
|
+
declare function printExpected(value: unknown): string;
|
|
1619
|
+
|
|
1620
|
+
declare function printReceived(object: unknown): string;
|
|
1621
|
+
|
|
1622
|
+
declare function printWithType<T>(name: string, value: T, print: (value: T) => string): string;
|
|
1623
|
+
|
|
479
1624
|
declare type Procedure = (...args: any[]) => any;
|
|
480
1625
|
|
|
481
|
-
declare type
|
|
482
|
-
|
|
1626
|
+
declare type Procedure_2 = (...args: any[]) => any;
|
|
1627
|
+
|
|
1628
|
+
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] };
|
|
1629
|
+
|
|
1630
|
+
declare type Promisify_2<O> = {
|
|
1631
|
+
[K in keyof O]: O[K] extends (...args: infer A) => infer R ? Promisify_2<O[K]> & ((...args: A) => Promise<R>) : O[K];
|
|
483
1632
|
};
|
|
484
1633
|
|
|
485
|
-
declare type PromisifyAssertion<T> = Promisify<
|
|
1634
|
+
declare type PromisifyAssertion<T> = Promisify<Assertion_2<T>>;
|
|
1635
|
+
|
|
1636
|
+
declare type PromisifyAssertion_2<T> = Promisify_2<Assertion<T>>;
|
|
1637
|
+
|
|
1638
|
+
declare interface RawMatcherFn<
|
|
1639
|
+
T extends MatcherState = MatcherState,
|
|
1640
|
+
E extends Array<any> = Array<any>
|
|
1641
|
+
> {
|
|
1642
|
+
(this: T, received: any, ...expected: E): ExpectationResult;
|
|
1643
|
+
}
|
|
1644
|
+
|
|
1645
|
+
declare interface RawSnapshotInfo {
|
|
1646
|
+
file: string;
|
|
1647
|
+
readonly?: boolean;
|
|
1648
|
+
content?: string;
|
|
1649
|
+
}
|
|
1650
|
+
|
|
1651
|
+
declare type Refs = Array<unknown>;
|
|
486
1652
|
|
|
487
1653
|
declare interface Reporter {
|
|
488
1654
|
/**
|
|
@@ -748,11 +1914,11 @@ declare interface RstestUtilities {
|
|
|
748
1914
|
/**
|
|
749
1915
|
* Creates a spy on a method of an object
|
|
750
1916
|
*/
|
|
751
|
-
spyOn: <T extends Record<string, any>, K extends keyof T>(obj: T, methodName: K, accessType?: 'get' | 'set') =>
|
|
1917
|
+
spyOn: <T extends Record<string, any>, K extends keyof T>(obj: T, methodName: K, accessType?: 'get' | 'set') => MockInstance_2<T[K]>;
|
|
752
1918
|
/**
|
|
753
1919
|
* Determines if the given function is a mocked function.
|
|
754
1920
|
*/
|
|
755
|
-
isMockFunction: (fn: any) => fn is
|
|
1921
|
+
isMockFunction: (fn: any) => fn is MockInstance_2;
|
|
756
1922
|
/**
|
|
757
1923
|
* Calls `.mockClear()` on all spies.
|
|
758
1924
|
*/
|
|
@@ -878,6 +2044,33 @@ declare type RuntimeConfig = Pick<RstestContext['normalizedConfig'], 'testTimeou
|
|
|
878
2044
|
|
|
879
2045
|
declare type RuntimeOptions = Partial<Pick<RuntimeConfig, 'testTimeout' | 'hookTimeout' | 'clearMocks' | 'resetMocks' | 'restoreMocks' | 'maxConcurrency' | 'retry'>>;
|
|
880
2046
|
|
|
2047
|
+
declare interface SaveStatus {
|
|
2048
|
+
deleted: boolean;
|
|
2049
|
+
saved: boolean;
|
|
2050
|
+
}
|
|
2051
|
+
|
|
2052
|
+
declare interface SnapshotEnvironment {
|
|
2053
|
+
getVersion: () => string;
|
|
2054
|
+
getHeader: () => string;
|
|
2055
|
+
resolvePath: (filepath: string) => Promise<string>;
|
|
2056
|
+
resolveRawPath: (testPath: string, rawPath: string) => Promise<string>;
|
|
2057
|
+
saveSnapshotFile: (filepath: string, snapshot: string) => Promise<void>;
|
|
2058
|
+
readSnapshotFile: (filepath: string) => Promise<string | null>;
|
|
2059
|
+
removeSnapshotFile: (filepath: string) => Promise<void>;
|
|
2060
|
+
processStackTrace?: (stack: ParsedStack) => ParsedStack;
|
|
2061
|
+
}
|
|
2062
|
+
|
|
2063
|
+
declare class SnapshotManager {
|
|
2064
|
+
options: Omit<SnapshotStateOptions, "snapshotEnvironment">;
|
|
2065
|
+
summary: SnapshotSummary;
|
|
2066
|
+
extension: string;
|
|
2067
|
+
constructor(options: Omit<SnapshotStateOptions, "snapshotEnvironment">);
|
|
2068
|
+
clear(): void;
|
|
2069
|
+
add(result: SnapshotResult): void;
|
|
2070
|
+
resolvePath<T = any>(testPath: string, context?: T): string;
|
|
2071
|
+
resolveRawPath(testPath: string, rawPath: string): string;
|
|
2072
|
+
}
|
|
2073
|
+
|
|
881
2074
|
declare interface SnapshotMatcher<T> {
|
|
882
2075
|
<U extends {
|
|
883
2076
|
[P in keyof T]: any;
|
|
@@ -885,6 +2078,109 @@ declare interface SnapshotMatcher<T> {
|
|
|
885
2078
|
(message?: string): void;
|
|
886
2079
|
}
|
|
887
2080
|
|
|
2081
|
+
declare interface SnapshotMatchOptions {
|
|
2082
|
+
testId: string;
|
|
2083
|
+
testName: string;
|
|
2084
|
+
received: unknown;
|
|
2085
|
+
key?: string;
|
|
2086
|
+
inlineSnapshot?: string;
|
|
2087
|
+
isInline: boolean;
|
|
2088
|
+
error?: Error;
|
|
2089
|
+
rawSnapshot?: RawSnapshotInfo;
|
|
2090
|
+
}
|
|
2091
|
+
|
|
2092
|
+
declare interface SnapshotResult {
|
|
2093
|
+
filepath: string;
|
|
2094
|
+
added: number;
|
|
2095
|
+
fileDeleted: boolean;
|
|
2096
|
+
matched: number;
|
|
2097
|
+
unchecked: number;
|
|
2098
|
+
uncheckedKeys: Array<string>;
|
|
2099
|
+
unmatched: number;
|
|
2100
|
+
updated: number;
|
|
2101
|
+
}
|
|
2102
|
+
|
|
2103
|
+
declare interface SnapshotReturnOptions {
|
|
2104
|
+
actual: string;
|
|
2105
|
+
count: number;
|
|
2106
|
+
expected?: string;
|
|
2107
|
+
key: string;
|
|
2108
|
+
pass: boolean;
|
|
2109
|
+
}
|
|
2110
|
+
|
|
2111
|
+
declare class SnapshotState {
|
|
2112
|
+
testFilePath: string;
|
|
2113
|
+
snapshotPath: string;
|
|
2114
|
+
private _counters;
|
|
2115
|
+
private _dirty;
|
|
2116
|
+
private _updateSnapshot;
|
|
2117
|
+
private _snapshotData;
|
|
2118
|
+
private _initialData;
|
|
2119
|
+
private _inlineSnapshots;
|
|
2120
|
+
private _inlineSnapshotStacks;
|
|
2121
|
+
private _testIdToKeys;
|
|
2122
|
+
private _rawSnapshots;
|
|
2123
|
+
private _uncheckedKeys;
|
|
2124
|
+
private _snapshotFormat;
|
|
2125
|
+
private _environment;
|
|
2126
|
+
private _fileExists;
|
|
2127
|
+
expand: boolean;
|
|
2128
|
+
// getter/setter for jest-image-snapshot compat
|
|
2129
|
+
// https://github.com/vitest-dev/vitest/issues/7322
|
|
2130
|
+
private _added;
|
|
2131
|
+
private _matched;
|
|
2132
|
+
private _unmatched;
|
|
2133
|
+
private _updated;
|
|
2134
|
+
get added(): CounterMap<string>;
|
|
2135
|
+
set added(value: CounterMap<string>);
|
|
2136
|
+
get matched(): CounterMap<string>;
|
|
2137
|
+
set matched(value: CounterMap<string>);
|
|
2138
|
+
get unmatched(): CounterMap<string>;
|
|
2139
|
+
set unmatched(value: CounterMap<string>);
|
|
2140
|
+
get updated(): CounterMap<string>;
|
|
2141
|
+
set updated(value: CounterMap<string>);
|
|
2142
|
+
private constructor();
|
|
2143
|
+
static create(testFilePath: string, options: SnapshotStateOptions): Promise<SnapshotState>;
|
|
2144
|
+
get environment(): SnapshotEnvironment;
|
|
2145
|
+
markSnapshotsAsCheckedForTest(testName: string): void;
|
|
2146
|
+
clearTest(testId: string): void;
|
|
2147
|
+
protected _inferInlineSnapshotStack(stacks: ParsedStack[]): ParsedStack | null;
|
|
2148
|
+
private _addSnapshot;
|
|
2149
|
+
save(): Promise<SaveStatus>;
|
|
2150
|
+
getUncheckedCount(): number;
|
|
2151
|
+
getUncheckedKeys(): Array<string>;
|
|
2152
|
+
removeUncheckedKeys(): void;
|
|
2153
|
+
match({ testId, testName, received, key, inlineSnapshot, isInline, error, rawSnapshot }: SnapshotMatchOptions): SnapshotReturnOptions;
|
|
2154
|
+
pack(): Promise<SnapshotResult>;
|
|
2155
|
+
}
|
|
2156
|
+
|
|
2157
|
+
declare interface SnapshotStateOptions {
|
|
2158
|
+
updateSnapshot: SnapshotUpdateState;
|
|
2159
|
+
snapshotEnvironment: SnapshotEnvironment;
|
|
2160
|
+
expand?: boolean;
|
|
2161
|
+
snapshotFormat?: OptionsReceived;
|
|
2162
|
+
resolveSnapshotPath?: (path: string, extension: string, context?: any) => string;
|
|
2163
|
+
}
|
|
2164
|
+
|
|
2165
|
+
declare interface SnapshotSummary {
|
|
2166
|
+
added: number;
|
|
2167
|
+
didUpdate: boolean;
|
|
2168
|
+
failure: boolean;
|
|
2169
|
+
filesAdded: number;
|
|
2170
|
+
filesRemoved: number;
|
|
2171
|
+
filesRemovedList: Array<string>;
|
|
2172
|
+
filesUnmatched: number;
|
|
2173
|
+
filesUpdated: number;
|
|
2174
|
+
matched: number;
|
|
2175
|
+
total: number;
|
|
2176
|
+
unchecked: number;
|
|
2177
|
+
uncheckedKeysByFile: Array<UncheckedSnapshot>;
|
|
2178
|
+
unmatched: number;
|
|
2179
|
+
updated: number;
|
|
2180
|
+
}
|
|
2181
|
+
|
|
2182
|
+
declare type SnapshotUpdateState = "all" | "new" | "none";
|
|
2183
|
+
|
|
888
2184
|
declare type SourceColumn = number;
|
|
889
2185
|
|
|
890
2186
|
declare type SourceLine = number;
|
|
@@ -927,10 +2223,25 @@ declare class StatusRenderer {
|
|
|
927
2223
|
clear(): void;
|
|
928
2224
|
}
|
|
929
2225
|
|
|
2226
|
+
declare function stringify(object: unknown, maxDepth?: number, { maxLength,...options }?: StringifyOptions): string;
|
|
2227
|
+
|
|
2228
|
+
declare interface StringifyOptions extends PrettyFormatOptions {
|
|
2229
|
+
maxLength?: number;
|
|
2230
|
+
}
|
|
2231
|
+
|
|
930
2232
|
declare type SuiteContext = {
|
|
931
2233
|
filepath: TestPath;
|
|
932
2234
|
};
|
|
933
2235
|
|
|
2236
|
+
declare interface SyncExpectationResult {
|
|
2237
|
+
pass: boolean;
|
|
2238
|
+
message: () => string;
|
|
2239
|
+
actual?: any;
|
|
2240
|
+
expected?: any;
|
|
2241
|
+
}
|
|
2242
|
+
|
|
2243
|
+
declare type Test = (arg0: any) => boolean;
|
|
2244
|
+
|
|
934
2245
|
export declare const test: Rstest['test'];
|
|
935
2246
|
|
|
936
2247
|
declare type TestAPI<ExtraContext = object> = TestFn<ExtraContext> & {
|
|
@@ -963,6 +2274,12 @@ declare interface TestEachFn {
|
|
|
963
2274
|
<T extends readonly [unknown, ...Array<unknown>]>(cases: ReadonlyArray<T>): (description: string, fn: (...args: [...T]) => MaybePromise<void>, timeout?: number) => void;
|
|
964
2275
|
}
|
|
965
2276
|
|
|
2277
|
+
declare type Tester = (this: TesterContext, a: any, b: any, customTesters: Array<Tester>) => boolean | undefined;
|
|
2278
|
+
|
|
2279
|
+
declare interface TesterContext {
|
|
2280
|
+
equals: (a: unknown, b: unknown, customTesters?: Array<Tester>, strictCheck?: boolean) => boolean;
|
|
2281
|
+
}
|
|
2282
|
+
|
|
966
2283
|
declare type TestFileInfo = {
|
|
967
2284
|
testPath: TestPath;
|
|
968
2285
|
};
|
|
@@ -1008,6 +2325,11 @@ declare class TraceMap implements SourceMap {
|
|
|
1008
2325
|
constructor(map: Ro<SourceMapInput>, mapUrl?: string | null);
|
|
1009
2326
|
}
|
|
1010
2327
|
|
|
2328
|
+
declare interface UncheckedSnapshot {
|
|
2329
|
+
filePath: string;
|
|
2330
|
+
keys: Array<string>;
|
|
2331
|
+
}
|
|
2332
|
+
|
|
1011
2333
|
declare type Use<T> = (value: T) => Promise<void>;
|
|
1012
2334
|
|
|
1013
2335
|
declare interface UserConsoleLog {
|
|
@@ -1022,6 +2344,13 @@ declare class VerboseReporter extends DefaultReporter {
|
|
|
1022
2344
|
onTestFileResult(test: TestFileResult): void;
|
|
1023
2345
|
}
|
|
1024
2346
|
|
|
2347
|
+
declare type VitestAssertion<
|
|
2348
|
+
A,
|
|
2349
|
+
T
|
|
2350
|
+
> = { [K in keyof A] : A[K] extends Chai.Assertion ? Assertion_2<T> : A[K] extends (...args: any[]) => any ? A[K] : VitestAssertion<A[K], T> } & ((type: string, message?: string) => Assertion_2);
|
|
2351
|
+
|
|
2352
|
+
declare type WithAsymmetricMatcher<T> = T | AsymmetricMatcher<unknown>;
|
|
2353
|
+
|
|
1025
2354
|
declare type XInput = {
|
|
1026
2355
|
x_google_ignoreList?: SourceMapV3['ignoreList'];
|
|
1027
2356
|
};
|