@vitest/expect 3.0.8 → 3.0.9

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/dist/index.d.ts CHANGED
@@ -13,716 +13,720 @@ declare function matcherHint(matcherName: string, received?: string, expected?:
13
13
  declare function printReceived(object: unknown): string;
14
14
  declare function printExpected(value: unknown): string;
15
15
  declare function getMatcherUtils(): {
16
- EXPECTED_COLOR: Formatter;
17
- RECEIVED_COLOR: Formatter;
18
- INVERTED_COLOR: Formatter;
19
- BOLD_WEIGHT: Formatter;
20
- DIM_COLOR: Formatter;
21
- diff: typeof diff;
22
- matcherHint: typeof matcherHint;
23
- printReceived: typeof printReceived;
24
- printExpected: typeof printExpected;
25
- printDiffOrStringify: typeof printDiffOrStringify;
16
+ EXPECTED_COLOR: Formatter
17
+ RECEIVED_COLOR: Formatter
18
+ INVERTED_COLOR: Formatter
19
+ BOLD_WEIGHT: Formatter
20
+ DIM_COLOR: Formatter
21
+ diff: typeof diff
22
+ matcherHint: typeof matcherHint
23
+ printReceived: typeof printReceived
24
+ printExpected: typeof printExpected
25
+ printDiffOrStringify: typeof printDiffOrStringify
26
26
  };
27
27
  declare function addCustomEqualityTesters(newTesters: Array<Tester>): void;
28
28
 
29
29
  /**
30
- * Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
31
- *
32
- * This source code is licensed under the MIT license found in the
33
- * LICENSE file in the root directory of this source tree.
34
- *
35
- */
30
+ * Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
31
+ *
32
+ * This source code is licensed under the MIT license found in the
33
+ * LICENSE file in the root directory of this source tree.
34
+ *
35
+ */
36
36
 
37
37
  type ChaiPlugin = Chai.ChaiPlugin;
38
38
  type Tester = (this: TesterContext, a: any, b: any, customTesters: Array<Tester>) => boolean | undefined;
39
39
  interface TesterContext {
40
- equals: (a: unknown, b: unknown, customTesters?: Array<Tester>, strictCheck?: boolean) => boolean;
40
+ equals: (a: unknown, b: unknown, customTesters?: Array<Tester>, strictCheck?: boolean) => boolean;
41
41
  }
42
42
 
43
43
  interface MatcherHintOptions {
44
- comment?: string;
45
- expectedColor?: Formatter;
46
- isDirectExpectCall?: boolean;
47
- isNot?: boolean;
48
- promise?: string;
49
- receivedColor?: Formatter;
50
- secondArgument?: string;
51
- secondArgumentColor?: Formatter;
44
+ comment?: string;
45
+ expectedColor?: Formatter;
46
+ isDirectExpectCall?: boolean;
47
+ isNot?: boolean;
48
+ promise?: string;
49
+ receivedColor?: Formatter;
50
+ secondArgument?: string;
51
+ secondArgumentColor?: Formatter;
52
52
  }
53
53
  interface MatcherState {
54
- customTesters: Array<Tester>;
55
- assertionCalls: number;
56
- currentTestName?: string;
57
- dontThrow?: () => void;
58
- error?: Error;
59
- equals: (a: unknown, b: unknown, customTesters?: Array<Tester>, strictCheck?: boolean) => boolean;
60
- expand?: boolean;
61
- expectedAssertionsNumber?: number | null;
62
- expectedAssertionsNumberErrorGen?: (() => Error) | null;
63
- isExpectingAssertions?: boolean;
64
- isExpectingAssertionsError?: Error | null;
65
- isNot: boolean;
66
- promise: string;
67
- suppressedErrors: Array<Error>;
68
- testPath?: string;
69
- utils: ReturnType<typeof getMatcherUtils> & {
70
- diff: typeof diff;
71
- stringify: typeof stringify;
72
- iterableEquality: Tester;
73
- subsetEquality: Tester;
74
- };
75
- soft?: boolean;
76
- poll?: boolean;
54
+ customTesters: Array<Tester>;
55
+ assertionCalls: number;
56
+ currentTestName?: string;
57
+ dontThrow?: () => void;
58
+ error?: Error;
59
+ equals: (a: unknown, b: unknown, customTesters?: Array<Tester>, strictCheck?: boolean) => boolean;
60
+ expand?: boolean;
61
+ expectedAssertionsNumber?: number | null;
62
+ expectedAssertionsNumberErrorGen?: (() => Error) | null;
63
+ isExpectingAssertions?: boolean;
64
+ isExpectingAssertionsError?: Error | null;
65
+ isNot: boolean;
66
+ promise: string;
67
+ suppressedErrors: Array<Error>;
68
+ testPath?: string;
69
+ utils: ReturnType<typeof getMatcherUtils> & {
70
+ diff: typeof diff
71
+ stringify: typeof stringify
72
+ iterableEquality: Tester
73
+ subsetEquality: Tester
74
+ };
75
+ soft?: boolean;
76
+ poll?: boolean;
77
77
  }
78
78
  interface SyncExpectationResult {
79
- pass: boolean;
80
- message: () => string;
81
- actual?: any;
82
- expected?: any;
79
+ pass: boolean;
80
+ message: () => string;
81
+ actual?: any;
82
+ expected?: any;
83
83
  }
84
84
  type AsyncExpectationResult = Promise<SyncExpectationResult>;
85
85
  type ExpectationResult = SyncExpectationResult | AsyncExpectationResult;
86
86
  interface RawMatcherFn<T extends MatcherState = MatcherState> {
87
- (this: T, received: any, ...expected: Array<any>): ExpectationResult;
87
+ (this: T, received: any, ...expected: Array<any>): ExpectationResult;
88
88
  }
89
89
  type MatchersObject<T extends MatcherState = MatcherState> = Record<string, RawMatcherFn<T>> & ThisType<T>;
90
90
  interface ExpectStatic extends Chai.ExpectStatic, AsymmetricMatchersContaining {
91
- <T>(actual: T, message?: string): Assertion<T>;
92
- extend: (expects: MatchersObject) => void;
93
- anything: () => any;
94
- any: (constructor: unknown) => any;
95
- getState: () => MatcherState;
96
- setState: (state: Partial<MatcherState>) => void;
97
- not: AsymmetricMatchersContaining;
91
+ <T>(actual: T, message?: string): Assertion<T>;
92
+ extend: (expects: MatchersObject) => void;
93
+ anything: () => any;
94
+ any: (constructor: unknown) => any;
95
+ getState: () => MatcherState;
96
+ setState: (state: Partial<MatcherState>) => void;
97
+ not: AsymmetricMatchersContaining;
98
98
  }
99
99
  interface CustomMatcher {
100
- /**
101
- * Checks that a value satisfies a custom matcher function.
102
- *
103
- * @param matcher - A function returning a boolean based on the custom condition
104
- * @param message - Optional custom error message on failure
105
- *
106
- * @example
107
- * expect(age).toSatisfy(val => val >= 18, 'Age must be at least 18');
108
- * expect(age).toEqual(expect.toSatisfy(val => val >= 18, 'Age must be at least 18'));
109
- */
110
- toSatisfy: (matcher: (value: any) => boolean, message?: string) => any;
111
- /**
112
- * Matches if the received value is one of the values in the expected array.
113
- *
114
- * @example
115
- * expect(1).toBeOneOf([1, 2, 3])
116
- * expect('foo').toBeOneOf([expect.any(String)])
117
- * expect({ a: 1 }).toEqual({ a: expect.toBeOneOf(['1', '2', '3']) })
118
- */
119
- toBeOneOf: <T>(sample: Array<T>) => any;
100
+ /**
101
+ * Checks that a value satisfies a custom matcher function.
102
+ *
103
+ * @param matcher - A function returning a boolean based on the custom condition
104
+ * @param message - Optional custom error message on failure
105
+ *
106
+ * @example
107
+ * expect(age).toSatisfy(val => val >= 18, 'Age must be at least 18');
108
+ * expect(age).toEqual(expect.toSatisfy(val => val >= 18, 'Age must be at least 18'));
109
+ */
110
+ toSatisfy: (matcher: (value: any) => boolean, message?: string) => any;
111
+ /**
112
+ * Matches if the received value is one of the values in the expected array.
113
+ *
114
+ * @example
115
+ * expect(1).toBeOneOf([1, 2, 3])
116
+ * expect('foo').toBeOneOf([expect.any(String)])
117
+ * expect({ a: 1 }).toEqual({ a: expect.toBeOneOf(['1', '2', '3']) })
118
+ */
119
+ toBeOneOf: <T>(sample: Array<T>) => any;
120
120
  }
121
121
  interface AsymmetricMatchersContaining extends CustomMatcher {
122
- /**
123
- * Matches if the received string contains the expected substring.
124
- *
125
- * @example
126
- * expect('I have an apple').toEqual(expect.stringContaining('apple'));
127
- * expect({ a: 'test string' }).toEqual({ a: expect.stringContaining('test') });
128
- */
129
- stringContaining: (expected: string) => any;
130
- /**
131
- * Matches if the received object contains all properties of the expected object.
132
- *
133
- * @example
134
- * expect({ a: '1', b: 2 }).toEqual(expect.objectContaining({ a: '1' }))
135
- */
136
- objectContaining: <T = any>(expected: T) => any;
137
- /**
138
- * Matches if the received array contains all elements in the expected array.
139
- *
140
- * @example
141
- * expect(['a', 'b', 'c']).toEqual(expect.arrayContaining(['b', 'a']));
142
- */
143
- arrayContaining: <T = unknown>(expected: Array<T>) => any;
144
- /**
145
- * Matches if the received string or regex matches the expected pattern.
146
- *
147
- * @example
148
- * expect('hello world').toEqual(expect.stringMatching(/^hello/));
149
- * expect('hello world').toEqual(expect.stringMatching('hello'));
150
- */
151
- stringMatching: (expected: string | RegExp) => any;
152
- /**
153
- * Matches if the received number is within a certain precision of the expected number.
154
- *
155
- * @param precision - Optional decimal precision for comparison. Default is 2.
156
- *
157
- * @example
158
- * expect(10.45).toEqual(expect.closeTo(10.5, 1));
159
- * expect(5.11).toEqual(expect.closeTo(5.12)); // with default precision
160
- */
161
- closeTo: (expected: number, precision?: number) => any;
122
+ /**
123
+ * Matches if the received string contains the expected substring.
124
+ *
125
+ * @example
126
+ * expect('I have an apple').toEqual(expect.stringContaining('apple'));
127
+ * expect({ a: 'test string' }).toEqual({ a: expect.stringContaining('test') });
128
+ */
129
+ stringContaining: (expected: string) => any;
130
+ /**
131
+ * Matches if the received object contains all properties of the expected object.
132
+ *
133
+ * @example
134
+ * expect({ a: '1', b: 2 }).toEqual(expect.objectContaining({ a: '1' }))
135
+ */
136
+ objectContaining: <T = any>(expected: T) => any;
137
+ /**
138
+ * Matches if the received array contains all elements in the expected array.
139
+ *
140
+ * @example
141
+ * expect(['a', 'b', 'c']).toEqual(expect.arrayContaining(['b', 'a']));
142
+ */
143
+ arrayContaining: <T = unknown>(expected: Array<T>) => any;
144
+ /**
145
+ * Matches if the received string or regex matches the expected pattern.
146
+ *
147
+ * @example
148
+ * expect('hello world').toEqual(expect.stringMatching(/^hello/));
149
+ * expect('hello world').toEqual(expect.stringMatching('hello'));
150
+ */
151
+ stringMatching: (expected: string | RegExp) => any;
152
+ /**
153
+ * Matches if the received number is within a certain precision of the expected number.
154
+ *
155
+ * @param precision - Optional decimal precision for comparison. Default is 2.
156
+ *
157
+ * @example
158
+ * expect(10.45).toEqual(expect.closeTo(10.5, 1));
159
+ * expect(5.11).toEqual(expect.closeTo(5.12)); // with default precision
160
+ */
161
+ closeTo: (expected: number, precision?: number) => any;
162
162
  }
163
163
  interface JestAssertion<T = any> extends jest.Matchers<void, T>, CustomMatcher {
164
- /**
165
- * Used when you want to check that two objects have the same value.
166
- * This matcher recursively checks the equality of all fields, rather than checking for object identity.
167
- *
168
- * @example
169
- * expect(user).toEqual({ name: 'Alice', age: 30 });
170
- */
171
- toEqual: <E>(expected: E) => void;
172
- /**
173
- * Use to test that objects have the same types as well as structure.
174
- *
175
- * @example
176
- * expect(user).toStrictEqual({ name: 'Alice', age: 30 });
177
- */
178
- toStrictEqual: <E>(expected: E) => void;
179
- /**
180
- * Checks that a value is what you expect. It calls `Object.is` to compare values.
181
- * Don't use `toBe` with floating-point numbers.
182
- *
183
- * @example
184
- * expect(result).toBe(42);
185
- * expect(status).toBe(true);
186
- */
187
- toBe: <E>(expected: E) => void;
188
- /**
189
- * Check that a string matches a regular expression.
190
- *
191
- * @example
192
- * expect(message).toMatch(/hello/);
193
- * expect(greeting).toMatch('world');
194
- */
195
- toMatch: (expected: string | RegExp) => void;
196
- /**
197
- * Used to check that a JavaScript object matches a subset of the properties of an object
198
- *
199
- * @example
200
- * expect(user).toMatchObject({
201
- * name: 'Alice',
202
- * address: { city: 'Wonderland' }
203
- * });
204
- */
205
- toMatchObject: <E extends object | any[]>(expected: E) => void;
206
- /**
207
- * Used when you want to check that an item is in a list.
208
- * For testing the items in the list, this uses `===`, a strict equality check.
209
- *
210
- * @example
211
- * expect(items).toContain('apple');
212
- * expect(numbers).toContain(5);
213
- */
214
- toContain: <E>(item: E) => void;
215
- /**
216
- * Used when you want to check that an item is in a list.
217
- * For testing the items in the list, this matcher recursively checks the
218
- * equality of all fields, rather than checking for object identity.
219
- *
220
- * @example
221
- * expect(items).toContainEqual({ name: 'apple', quantity: 1 });
222
- */
223
- toContainEqual: <E>(item: E) => void;
224
- /**
225
- * Use when you don't care what a value is, you just want to ensure a value
226
- * is true in a boolean context. In JavaScript, there are six falsy values:
227
- * `false`, `0`, `''`, `null`, `undefined`, and `NaN`. Everything else is truthy.
228
- *
229
- * @example
230
- * expect(user.isActive).toBeTruthy();
231
- */
232
- toBeTruthy: () => void;
233
- /**
234
- * When you don't care what a value is, you just want to
235
- * ensure a value is false in a boolean context.
236
- *
237
- * @example
238
- * expect(user.isActive).toBeFalsy();
239
- */
240
- toBeFalsy: () => void;
241
- /**
242
- * For comparing floating point numbers.
243
- *
244
- * @example
245
- * expect(score).toBeGreaterThan(10);
246
- */
247
- toBeGreaterThan: (num: number | bigint) => void;
248
- /**
249
- * For comparing floating point numbers.
250
- *
251
- * @example
252
- * expect(score).toBeGreaterThanOrEqual(10);
253
- */
254
- toBeGreaterThanOrEqual: (num: number | bigint) => void;
255
- /**
256
- * For comparing floating point numbers.
257
- *
258
- * @example
259
- * expect(score).toBeLessThan(10);
260
- */
261
- toBeLessThan: (num: number | bigint) => void;
262
- /**
263
- * For comparing floating point numbers.
264
- *
265
- * @example
266
- * expect(score).toBeLessThanOrEqual(10);
267
- */
268
- toBeLessThanOrEqual: (num: number | bigint) => void;
269
- /**
270
- * Used to check that a variable is NaN.
271
- *
272
- * @example
273
- * expect(value).toBeNaN();
274
- */
275
- toBeNaN: () => void;
276
- /**
277
- * Used to check that a variable is undefined.
278
- *
279
- * @example
280
- * expect(value).toBeUndefined();
281
- */
282
- toBeUndefined: () => void;
283
- /**
284
- * This is the same as `.toBe(null)` but the error messages are a bit nicer.
285
- * So use `.toBeNull()` when you want to check that something is null.
286
- *
287
- * @example
288
- * expect(value).toBeNull();
289
- */
290
- toBeNull: () => void;
291
- /**
292
- * Ensure that a variable is not undefined.
293
- *
294
- * @example
295
- * expect(value).toBeDefined();
296
- */
297
- toBeDefined: () => void;
298
- /**
299
- * Ensure that an object is an instance of a class.
300
- * This matcher uses `instanceof` underneath.
301
- *
302
- * @example
303
- * expect(new Date()).toBeInstanceOf(Date);
304
- */
305
- toBeInstanceOf: <E>(expected: E) => void;
306
- /**
307
- * Used to check that an object has a `.length` property
308
- * and it is set to a certain numeric value.
309
- *
310
- * @example
311
- * expect([1, 2, 3]).toHaveLength(3);
312
- * expect('hello').toHaveLength(5);
313
- */
314
- toHaveLength: (length: number) => void;
315
- /**
316
- * Use to check if a property at the specified path exists on an object.
317
- * For checking deeply nested properties, you may use dot notation or an array containing
318
- * the path segments for deep references.
319
- *
320
- * Optionally, you can provide a value to check if it matches the value present at the path
321
- * on the target object. This matcher uses 'deep equality' (like `toEqual()`) and recursively checks
322
- * the equality of all fields.
323
- *
324
- * @example
325
- * expect(user).toHaveProperty('address.city', 'New York');
326
- * expect(config).toHaveProperty(['settings', 'theme'], 'dark');
327
- */
328
- toHaveProperty: <E>(property: string | (string | number)[], value?: E) => void;
329
- /**
330
- * Using exact equality with floating point numbers is a bad idea.
331
- * Rounding means that intuitive things fail.
332
- * The default for `precision` is 2.
333
- *
334
- * @example
335
- * expect(price).toBeCloseTo(9.99, 2);
336
- */
337
- toBeCloseTo: (number: number, numDigits?: number) => void;
338
- /**
339
- * Ensures that a mock function is called an exact number of times.
340
- *
341
- * Also under the alias `expect.toBeCalledTimes`.
342
- *
343
- * @example
344
- * expect(mockFunc).toHaveBeenCalledTimes(2);
345
- */
346
- toHaveBeenCalledTimes: (times: number) => void;
347
- /**
348
- * Ensures that a mock function is called an exact number of times.
349
- *
350
- * Alias for `expect.toHaveBeenCalledTimes`.
351
- *
352
- * @example
353
- * expect(mockFunc).toBeCalledTimes(2);
354
- */
355
- toBeCalledTimes: (times: number) => void;
356
- /**
357
- * Ensures that a mock function is called.
358
- *
359
- * Also under the alias `expect.toBeCalled`.
360
- *
361
- * @example
362
- * expect(mockFunc).toHaveBeenCalled();
363
- */
364
- toHaveBeenCalled: () => void;
365
- /**
366
- * Ensures that a mock function is called.
367
- *
368
- * Alias for `expect.toHaveBeenCalled`.
369
- *
370
- * @example
371
- * expect(mockFunc).toBeCalled();
372
- */
373
- toBeCalled: () => void;
374
- /**
375
- * Ensure that a mock function is called with specific arguments.
376
- *
377
- * Also under the alias `expect.toBeCalledWith`.
378
- *
379
- * @example
380
- * expect(mockFunc).toHaveBeenCalledWith('arg1', 42);
381
- */
382
- toHaveBeenCalledWith: <E extends any[]>(...args: E) => void;
383
- /**
384
- * Ensure that a mock function is called with specific arguments.
385
- *
386
- * Alias for `expect.toHaveBeenCalledWith`.
387
- *
388
- * @example
389
- * expect(mockFunc).toBeCalledWith('arg1', 42);
390
- */
391
- toBeCalledWith: <E extends any[]>(...args: E) => void;
392
- /**
393
- * Ensure that a mock function is called with specific arguments on an Nth call.
394
- *
395
- * Also under the alias `expect.nthCalledWith`.
396
- *
397
- * @example
398
- * expect(mockFunc).toHaveBeenNthCalledWith(2, 'secondArg');
399
- */
400
- toHaveBeenNthCalledWith: <E extends any[]>(n: number, ...args: E) => void;
401
- /**
402
- * Ensure that a mock function is called with specific arguments on an Nth call.
403
- *
404
- * Alias for `expect.toHaveBeenNthCalledWith`.
405
- *
406
- * @example
407
- * expect(mockFunc).nthCalledWith(2, 'secondArg');
408
- */
409
- nthCalledWith: <E extends any[]>(nthCall: number, ...args: E) => void;
410
- /**
411
- * If you have a mock function, you can use `.toHaveBeenLastCalledWith`
412
- * to test what arguments it was last called with.
413
- *
414
- * Also under the alias `expect.lastCalledWith`.
415
- *
416
- * @example
417
- * expect(mockFunc).toHaveBeenLastCalledWith('lastArg');
418
- */
419
- toHaveBeenLastCalledWith: <E extends any[]>(...args: E) => void;
420
- /**
421
- * If you have a mock function, you can use `.lastCalledWith`
422
- * to test what arguments it was last called with.
423
- *
424
- * Alias for `expect.toHaveBeenLastCalledWith`.
425
- *
426
- * @example
427
- * expect(mockFunc).lastCalledWith('lastArg');
428
- */
429
- lastCalledWith: <E extends any[]>(...args: E) => void;
430
- /**
431
- * Used to test that a function throws when it is called.
432
- *
433
- * Also under the alias `expect.toThrowError`.
434
- *
435
- * @example
436
- * expect(() => functionWithError()).toThrow('Error message');
437
- * expect(() => parseJSON('invalid')).toThrow(SyntaxError);
438
- */
439
- toThrow: (expected?: string | Constructable | RegExp | Error) => void;
440
- /**
441
- * Used to test that a function throws when it is called.
442
- *
443
- * Alias for `expect.toThrow`.
444
- *
445
- * @example
446
- * expect(() => functionWithError()).toThrowError('Error message');
447
- * expect(() => parseJSON('invalid')).toThrowError(SyntaxError);
448
- */
449
- toThrowError: (expected?: string | Constructable | RegExp | Error) => void;
450
- /**
451
- * Use to test that the mock function successfully returned (i.e., did not throw an error) at least one time
452
- *
453
- * Alias for `expect.toHaveReturned`.
454
- *
455
- * @example
456
- * expect(mockFunc).toReturn();
457
- */
458
- toReturn: () => void;
459
- /**
460
- * Use to test that the mock function successfully returned (i.e., did not throw an error) at least one time
461
- *
462
- * Also under the alias `expect.toReturn`.
463
- *
464
- * @example
465
- * expect(mockFunc).toHaveReturned();
466
- */
467
- toHaveReturned: () => void;
468
- /**
469
- * Use to ensure that a mock function returned successfully (i.e., did not throw an error) an exact number of times.
470
- * Any calls to the mock function that throw an error are not counted toward the number of times the function returned.
471
- *
472
- * Alias for `expect.toHaveReturnedTimes`.
473
- *
474
- * @example
475
- * expect(mockFunc).toReturnTimes(3);
476
- */
477
- toReturnTimes: (times: number) => void;
478
- /**
479
- * Use to ensure that a mock function returned successfully (i.e., did not throw an error) an exact number of times.
480
- * Any calls to the mock function that throw an error are not counted toward the number of times the function returned.
481
- *
482
- * Also under the alias `expect.toReturnTimes`.
483
- *
484
- * @example
485
- * expect(mockFunc).toHaveReturnedTimes(3);
486
- */
487
- toHaveReturnedTimes: (times: number) => void;
488
- /**
489
- * Use to ensure that a mock function returned a specific value.
490
- *
491
- * Alias for `expect.toHaveReturnedWith`.
492
- *
493
- * @example
494
- * expect(mockFunc).toReturnWith('returnValue');
495
- */
496
- toReturnWith: <E>(value: E) => void;
497
- /**
498
- * Use to ensure that a mock function returned a specific value.
499
- *
500
- * Also under the alias `expect.toReturnWith`.
501
- *
502
- * @example
503
- * expect(mockFunc).toHaveReturnedWith('returnValue');
504
- */
505
- toHaveReturnedWith: <E>(value: E) => void;
506
- /**
507
- * Use to test the specific value that a mock function last returned.
508
- * If the last call to the mock function threw an error, then this matcher will fail
509
- * no matter what value you provided as the expected return value.
510
- *
511
- * Also under the alias `expect.lastReturnedWith`.
512
- *
513
- * @example
514
- * expect(mockFunc).toHaveLastReturnedWith('lastValue');
515
- */
516
- toHaveLastReturnedWith: <E>(value: E) => void;
517
- /**
518
- * Use to test the specific value that a mock function last returned.
519
- * If the last call to the mock function threw an error, then this matcher will fail
520
- * no matter what value you provided as the expected return value.
521
- *
522
- * Alias for `expect.toHaveLastReturnedWith`.
523
- *
524
- * @example
525
- * expect(mockFunc).lastReturnedWith('lastValue');
526
- */
527
- lastReturnedWith: <E>(value: E) => void;
528
- /**
529
- * Use to test the specific value that a mock function returned for the nth call.
530
- * If the nth call to the mock function threw an error, then this matcher will fail
531
- * no matter what value you provided as the expected return value.
532
- *
533
- * Also under the alias `expect.nthReturnedWith`.
534
- *
535
- * @example
536
- * expect(mockFunc).toHaveNthReturnedWith(2, 'nthValue');
537
- */
538
- toHaveNthReturnedWith: <E>(nthCall: number, value: E) => void;
539
- /**
540
- * Use to test the specific value that a mock function returned for the nth call.
541
- * If the nth call to the mock function threw an error, then this matcher will fail
542
- * no matter what value you provided as the expected return value.
543
- *
544
- * Alias for `expect.toHaveNthReturnedWith`.
545
- *
546
- * @example
547
- * expect(mockFunc).nthReturnedWith(2, 'nthValue');
548
- */
549
- nthReturnedWith: <E>(nthCall: number, value: E) => void;
164
+ /**
165
+ * Used when you want to check that two objects have the same value.
166
+ * This matcher recursively checks the equality of all fields, rather than checking for object identity.
167
+ *
168
+ * @example
169
+ * expect(user).toEqual({ name: 'Alice', age: 30 });
170
+ */
171
+ toEqual: <E>(expected: E) => void;
172
+ /**
173
+ * Use to test that objects have the same types as well as structure.
174
+ *
175
+ * @example
176
+ * expect(user).toStrictEqual({ name: 'Alice', age: 30 });
177
+ */
178
+ toStrictEqual: <E>(expected: E) => void;
179
+ /**
180
+ * Checks that a value is what you expect. It calls `Object.is` to compare values.
181
+ * Don't use `toBe` with floating-point numbers.
182
+ *
183
+ * @example
184
+ * expect(result).toBe(42);
185
+ * expect(status).toBe(true);
186
+ */
187
+ toBe: <E>(expected: E) => void;
188
+ /**
189
+ * Check that a string matches a regular expression.
190
+ *
191
+ * @example
192
+ * expect(message).toMatch(/hello/);
193
+ * expect(greeting).toMatch('world');
194
+ */
195
+ toMatch: (expected: string | RegExp) => void;
196
+ /**
197
+ * Used to check that a JavaScript object matches a subset of the properties of an object
198
+ *
199
+ * @example
200
+ * expect(user).toMatchObject({
201
+ * name: 'Alice',
202
+ * address: { city: 'Wonderland' }
203
+ * });
204
+ */
205
+ toMatchObject: <E extends object | any[]>(expected: E) => void;
206
+ /**
207
+ * Used when you want to check that an item is in a list.
208
+ * For testing the items in the list, this uses `===`, a strict equality check.
209
+ *
210
+ * @example
211
+ * expect(items).toContain('apple');
212
+ * expect(numbers).toContain(5);
213
+ */
214
+ toContain: <E>(item: E) => void;
215
+ /**
216
+ * Used when you want to check that an item is in a list.
217
+ * For testing the items in the list, this matcher recursively checks the
218
+ * equality of all fields, rather than checking for object identity.
219
+ *
220
+ * @example
221
+ * expect(items).toContainEqual({ name: 'apple', quantity: 1 });
222
+ */
223
+ toContainEqual: <E>(item: E) => void;
224
+ /**
225
+ * Use when you don't care what a value is, you just want to ensure a value
226
+ * is true in a boolean context. In JavaScript, there are six falsy values:
227
+ * `false`, `0`, `''`, `null`, `undefined`, and `NaN`. Everything else is truthy.
228
+ *
229
+ * @example
230
+ * expect(user.isActive).toBeTruthy();
231
+ */
232
+ toBeTruthy: () => void;
233
+ /**
234
+ * When you don't care what a value is, you just want to
235
+ * ensure a value is false in a boolean context.
236
+ *
237
+ * @example
238
+ * expect(user.isActive).toBeFalsy();
239
+ */
240
+ toBeFalsy: () => void;
241
+ /**
242
+ * For comparing floating point numbers.
243
+ *
244
+ * @example
245
+ * expect(score).toBeGreaterThan(10);
246
+ */
247
+ toBeGreaterThan: (num: number | bigint) => void;
248
+ /**
249
+ * For comparing floating point numbers.
250
+ *
251
+ * @example
252
+ * expect(score).toBeGreaterThanOrEqual(10);
253
+ */
254
+ toBeGreaterThanOrEqual: (num: number | bigint) => void;
255
+ /**
256
+ * For comparing floating point numbers.
257
+ *
258
+ * @example
259
+ * expect(score).toBeLessThan(10);
260
+ */
261
+ toBeLessThan: (num: number | bigint) => void;
262
+ /**
263
+ * For comparing floating point numbers.
264
+ *
265
+ * @example
266
+ * expect(score).toBeLessThanOrEqual(10);
267
+ */
268
+ toBeLessThanOrEqual: (num: number | bigint) => void;
269
+ /**
270
+ * Used to check that a variable is NaN.
271
+ *
272
+ * @example
273
+ * expect(value).toBeNaN();
274
+ */
275
+ toBeNaN: () => void;
276
+ /**
277
+ * Used to check that a variable is undefined.
278
+ *
279
+ * @example
280
+ * expect(value).toBeUndefined();
281
+ */
282
+ toBeUndefined: () => void;
283
+ /**
284
+ * This is the same as `.toBe(null)` but the error messages are a bit nicer.
285
+ * So use `.toBeNull()` when you want to check that something is null.
286
+ *
287
+ * @example
288
+ * expect(value).toBeNull();
289
+ */
290
+ toBeNull: () => void;
291
+ /**
292
+ * Ensure that a variable is not undefined.
293
+ *
294
+ * @example
295
+ * expect(value).toBeDefined();
296
+ */
297
+ toBeDefined: () => void;
298
+ /**
299
+ * Ensure that an object is an instance of a class.
300
+ * This matcher uses `instanceof` underneath.
301
+ *
302
+ * @example
303
+ * expect(new Date()).toBeInstanceOf(Date);
304
+ */
305
+ toBeInstanceOf: <E>(expected: E) => void;
306
+ /**
307
+ * Used to check that an object has a `.length` property
308
+ * and it is set to a certain numeric value.
309
+ *
310
+ * @example
311
+ * expect([1, 2, 3]).toHaveLength(3);
312
+ * expect('hello').toHaveLength(5);
313
+ */
314
+ toHaveLength: (length: number) => void;
315
+ /**
316
+ * Use to check if a property at the specified path exists on an object.
317
+ * For checking deeply nested properties, you may use dot notation or an array containing
318
+ * the path segments for deep references.
319
+ *
320
+ * Optionally, you can provide a value to check if it matches the value present at the path
321
+ * on the target object. This matcher uses 'deep equality' (like `toEqual()`) and recursively checks
322
+ * the equality of all fields.
323
+ *
324
+ * @example
325
+ * expect(user).toHaveProperty('address.city', 'New York');
326
+ * expect(config).toHaveProperty(['settings', 'theme'], 'dark');
327
+ */
328
+ toHaveProperty: <E>(property: string | (string | number)[], value?: E) => void;
329
+ /**
330
+ * Using exact equality with floating point numbers is a bad idea.
331
+ * Rounding means that intuitive things fail.
332
+ * The default for `precision` is 2.
333
+ *
334
+ * @example
335
+ * expect(price).toBeCloseTo(9.99, 2);
336
+ */
337
+ toBeCloseTo: (number: number, numDigits?: number) => void;
338
+ /**
339
+ * Ensures that a mock function is called an exact number of times.
340
+ *
341
+ * Also under the alias `expect.toBeCalledTimes`.
342
+ *
343
+ * @example
344
+ * expect(mockFunc).toHaveBeenCalledTimes(2);
345
+ */
346
+ toHaveBeenCalledTimes: (times: number) => void;
347
+ /**
348
+ * Ensures that a mock function is called an exact number of times.
349
+ *
350
+ * Alias for `expect.toHaveBeenCalledTimes`.
351
+ *
352
+ * @example
353
+ * expect(mockFunc).toBeCalledTimes(2);
354
+ */
355
+ toBeCalledTimes: (times: number) => void;
356
+ /**
357
+ * Ensures that a mock function is called.
358
+ *
359
+ * Also under the alias `expect.toBeCalled`.
360
+ *
361
+ * @example
362
+ * expect(mockFunc).toHaveBeenCalled();
363
+ */
364
+ toHaveBeenCalled: () => void;
365
+ /**
366
+ * Ensures that a mock function is called.
367
+ *
368
+ * Alias for `expect.toHaveBeenCalled`.
369
+ *
370
+ * @example
371
+ * expect(mockFunc).toBeCalled();
372
+ */
373
+ toBeCalled: () => void;
374
+ /**
375
+ * Ensure that a mock function is called with specific arguments.
376
+ *
377
+ * Also under the alias `expect.toBeCalledWith`.
378
+ *
379
+ * @example
380
+ * expect(mockFunc).toHaveBeenCalledWith('arg1', 42);
381
+ */
382
+ toHaveBeenCalledWith: <E extends any[]>(...args: E) => void;
383
+ /**
384
+ * Ensure that a mock function is called with specific arguments.
385
+ *
386
+ * Alias for `expect.toHaveBeenCalledWith`.
387
+ *
388
+ * @example
389
+ * expect(mockFunc).toBeCalledWith('arg1', 42);
390
+ */
391
+ toBeCalledWith: <E extends any[]>(...args: E) => void;
392
+ /**
393
+ * Ensure that a mock function is called with specific arguments on an Nth call.
394
+ *
395
+ * Also under the alias `expect.nthCalledWith`.
396
+ *
397
+ * @example
398
+ * expect(mockFunc).toHaveBeenNthCalledWith(2, 'secondArg');
399
+ */
400
+ toHaveBeenNthCalledWith: <E extends any[]>(n: number, ...args: E) => void;
401
+ /**
402
+ * Ensure that a mock function is called with specific arguments on an Nth call.
403
+ *
404
+ * Alias for `expect.toHaveBeenNthCalledWith`.
405
+ *
406
+ * @example
407
+ * expect(mockFunc).nthCalledWith(2, 'secondArg');
408
+ */
409
+ nthCalledWith: <E extends any[]>(nthCall: number, ...args: E) => void;
410
+ /**
411
+ * If you have a mock function, you can use `.toHaveBeenLastCalledWith`
412
+ * to test what arguments it was last called with.
413
+ *
414
+ * Also under the alias `expect.lastCalledWith`.
415
+ *
416
+ * @example
417
+ * expect(mockFunc).toHaveBeenLastCalledWith('lastArg');
418
+ */
419
+ toHaveBeenLastCalledWith: <E extends any[]>(...args: E) => void;
420
+ /**
421
+ * If you have a mock function, you can use `.lastCalledWith`
422
+ * to test what arguments it was last called with.
423
+ *
424
+ * Alias for `expect.toHaveBeenLastCalledWith`.
425
+ *
426
+ * @example
427
+ * expect(mockFunc).lastCalledWith('lastArg');
428
+ */
429
+ lastCalledWith: <E extends any[]>(...args: E) => void;
430
+ /**
431
+ * Used to test that a function throws when it is called.
432
+ *
433
+ * Also under the alias `expect.toThrowError`.
434
+ *
435
+ * @example
436
+ * expect(() => functionWithError()).toThrow('Error message');
437
+ * expect(() => parseJSON('invalid')).toThrow(SyntaxError);
438
+ */
439
+ toThrow: (expected?: string | Constructable | RegExp | Error) => void;
440
+ /**
441
+ * Used to test that a function throws when it is called.
442
+ *
443
+ * Alias for `expect.toThrow`.
444
+ *
445
+ * @example
446
+ * expect(() => functionWithError()).toThrowError('Error message');
447
+ * expect(() => parseJSON('invalid')).toThrowError(SyntaxError);
448
+ */
449
+ toThrowError: (expected?: string | Constructable | RegExp | Error) => void;
450
+ /**
451
+ * Use to test that the mock function successfully returned (i.e., did not throw an error) at least one time
452
+ *
453
+ * Alias for `expect.toHaveReturned`.
454
+ *
455
+ * @example
456
+ * expect(mockFunc).toReturn();
457
+ */
458
+ toReturn: () => void;
459
+ /**
460
+ * Use to test that the mock function successfully returned (i.e., did not throw an error) at least one time
461
+ *
462
+ * Also under the alias `expect.toReturn`.
463
+ *
464
+ * @example
465
+ * expect(mockFunc).toHaveReturned();
466
+ */
467
+ toHaveReturned: () => void;
468
+ /**
469
+ * Use to ensure that a mock function returned successfully (i.e., did not throw an error) an exact number of times.
470
+ * Any calls to the mock function that throw an error are not counted toward the number of times the function returned.
471
+ *
472
+ * Alias for `expect.toHaveReturnedTimes`.
473
+ *
474
+ * @example
475
+ * expect(mockFunc).toReturnTimes(3);
476
+ */
477
+ toReturnTimes: (times: number) => void;
478
+ /**
479
+ * Use to ensure that a mock function returned successfully (i.e., did not throw an error) an exact number of times.
480
+ * Any calls to the mock function that throw an error are not counted toward the number of times the function returned.
481
+ *
482
+ * Also under the alias `expect.toReturnTimes`.
483
+ *
484
+ * @example
485
+ * expect(mockFunc).toHaveReturnedTimes(3);
486
+ */
487
+ toHaveReturnedTimes: (times: number) => void;
488
+ /**
489
+ * Use to ensure that a mock function returned a specific value.
490
+ *
491
+ * Alias for `expect.toHaveReturnedWith`.
492
+ *
493
+ * @example
494
+ * expect(mockFunc).toReturnWith('returnValue');
495
+ */
496
+ toReturnWith: <E>(value: E) => void;
497
+ /**
498
+ * Use to ensure that a mock function returned a specific value.
499
+ *
500
+ * Also under the alias `expect.toReturnWith`.
501
+ *
502
+ * @example
503
+ * expect(mockFunc).toHaveReturnedWith('returnValue');
504
+ */
505
+ toHaveReturnedWith: <E>(value: E) => void;
506
+ /**
507
+ * Use to test the specific value that a mock function last returned.
508
+ * If the last call to the mock function threw an error, then this matcher will fail
509
+ * no matter what value you provided as the expected return value.
510
+ *
511
+ * Also under the alias `expect.lastReturnedWith`.
512
+ *
513
+ * @example
514
+ * expect(mockFunc).toHaveLastReturnedWith('lastValue');
515
+ */
516
+ toHaveLastReturnedWith: <E>(value: E) => void;
517
+ /**
518
+ * Use to test the specific value that a mock function last returned.
519
+ * If the last call to the mock function threw an error, then this matcher will fail
520
+ * no matter what value you provided as the expected return value.
521
+ *
522
+ * Alias for `expect.toHaveLastReturnedWith`.
523
+ *
524
+ * @example
525
+ * expect(mockFunc).lastReturnedWith('lastValue');
526
+ */
527
+ lastReturnedWith: <E>(value: E) => void;
528
+ /**
529
+ * Use to test the specific value that a mock function returned for the nth call.
530
+ * If the nth call to the mock function threw an error, then this matcher will fail
531
+ * no matter what value you provided as the expected return value.
532
+ *
533
+ * Also under the alias `expect.nthReturnedWith`.
534
+ *
535
+ * @example
536
+ * expect(mockFunc).toHaveNthReturnedWith(2, 'nthValue');
537
+ */
538
+ toHaveNthReturnedWith: <E>(nthCall: number, value: E) => void;
539
+ /**
540
+ * Use to test the specific value that a mock function returned for the nth call.
541
+ * If the nth call to the mock function threw an error, then this matcher will fail
542
+ * no matter what value you provided as the expected return value.
543
+ *
544
+ * Alias for `expect.toHaveNthReturnedWith`.
545
+ *
546
+ * @example
547
+ * expect(mockFunc).nthReturnedWith(2, 'nthValue');
548
+ */
549
+ nthReturnedWith: <E>(nthCall: number, value: E) => void;
550
550
  }
551
- type VitestAssertion<A, T> = {
552
- [K in keyof A]: A[K] extends Chai.Assertion ? Assertion<T> : A[K] extends (...args: any[]) => any ? A[K] : VitestAssertion<A[K], T>;
553
- } & ((type: string, message?: string) => Assertion);
554
- type Promisify<O> = {
555
- [K in keyof O]: O[K] extends (...args: infer A) => infer R ? Promisify<O[K]> & ((...args: A) => Promise<R>) : O[K];
556
- };
551
+ type VitestAssertion<
552
+ A,
553
+ T
554
+ > = { [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);
555
+ type Promisify<O> = { [K in keyof O] : O[K] extends (...args: infer A) => infer R ? Promisify<O[K]> & ((...args: A) => Promise<R>) : O[K] };
557
556
  type PromisifyAssertion<T> = Promisify<Assertion<T>>;
558
557
  interface Assertion<T = any> extends VitestAssertion<Chai.Assertion, T>, JestAssertion<T> {
559
- /**
560
- * Ensures a value is of a specific type.
561
- *
562
- * @example
563
- * expect(value).toBeTypeOf('string');
564
- * expect(number).toBeTypeOf('number');
565
- */
566
- toBeTypeOf: (expected: 'bigint' | 'boolean' | 'function' | 'number' | 'object' | 'string' | 'symbol' | 'undefined') => void;
567
- /**
568
- * Asserts that a mock function was called exactly once.
569
- *
570
- * @example
571
- * expect(mockFunc).toHaveBeenCalledOnce();
572
- */
573
- toHaveBeenCalledOnce: () => void;
574
- /**
575
- * Ensure that a mock function is called with specific arguments and called
576
- * exactly once.
577
- *
578
- * @example
579
- * expect(mockFunc).toHaveBeenCalledExactlyOnceWith('arg1', 42);
580
- */
581
- toHaveBeenCalledExactlyOnceWith: <E extends any[]>(...args: E) => void;
582
- /**
583
- * This assertion checks if a `Mock` was called before another `Mock`.
584
- * @param mock - A mock function created by `vi.spyOn` or `vi.fn`
585
- * @param failIfNoFirstInvocation - Fail if the first mock was never called
586
- * @example
587
- * const mock1 = vi.fn()
588
- * const mock2 = vi.fn()
589
- *
590
- * mock1()
591
- * mock2()
592
- * mock1()
593
- *
594
- * expect(mock1).toHaveBeenCalledBefore(mock2)
595
- */
596
- toHaveBeenCalledBefore: (mock: MockInstance, failIfNoFirstInvocation?: boolean) => void;
597
- /**
598
- * This assertion checks if a `Mock` was called after another `Mock`.
599
- * @param mock - A mock function created by `vi.spyOn` or `vi.fn`
600
- * @param failIfNoFirstInvocation - Fail if the first mock was never called
601
- * @example
602
- * const mock1 = vi.fn()
603
- * const mock2 = vi.fn()
604
- *
605
- * mock2()
606
- * mock1()
607
- * mock2()
608
- *
609
- * expect(mock1).toHaveBeenCalledAfter(mock2)
610
- */
611
- toHaveBeenCalledAfter: (mock: MockInstance, failIfNoFirstInvocation?: boolean) => void;
612
- /**
613
- * Checks that a promise resolves successfully at least once.
614
- *
615
- * @example
616
- * await expect(promise).toHaveResolved();
617
- */
618
- toHaveResolved: () => void;
619
- /**
620
- * Checks that a promise resolves to a specific value.
621
- *
622
- * @example
623
- * await expect(promise).toHaveResolvedWith('success');
624
- */
625
- toHaveResolvedWith: <E>(value: E) => void;
626
- /**
627
- * Ensures a promise resolves a specific number of times.
628
- *
629
- * @example
630
- * expect(mockAsyncFunc).toHaveResolvedTimes(3);
631
- */
632
- toHaveResolvedTimes: (times: number) => void;
633
- /**
634
- * Asserts that the last resolved value of a promise matches an expected value.
635
- *
636
- * @example
637
- * await expect(mockAsyncFunc).toHaveLastResolvedWith('finalResult');
638
- */
639
- toHaveLastResolvedWith: <E>(value: E) => void;
640
- /**
641
- * Ensures a specific value was returned by a promise on the nth resolution.
642
- *
643
- * @example
644
- * await expect(mockAsyncFunc).toHaveNthResolvedWith(2, 'secondResult');
645
- */
646
- toHaveNthResolvedWith: <E>(nthCall: number, value: E) => void;
647
- /**
648
- * Verifies that a promise resolves.
649
- *
650
- * @example
651
- * await expect(someAsyncFunc).resolves.toBe(42);
652
- */
653
- resolves: PromisifyAssertion<T>;
654
- /**
655
- * Verifies that a promise rejects.
656
- *
657
- * @example
658
- * await expect(someAsyncFunc).rejects.toThrow('error');
659
- */
660
- rejects: PromisifyAssertion<T>;
558
+ /**
559
+ * Ensures a value is of a specific type.
560
+ *
561
+ * @example
562
+ * expect(value).toBeTypeOf('string');
563
+ * expect(number).toBeTypeOf('number');
564
+ */
565
+ toBeTypeOf: (expected: "bigint" | "boolean" | "function" | "number" | "object" | "string" | "symbol" | "undefined") => void;
566
+ /**
567
+ * Asserts that a mock function was called exactly once.
568
+ *
569
+ * @example
570
+ * expect(mockFunc).toHaveBeenCalledOnce();
571
+ */
572
+ toHaveBeenCalledOnce: () => void;
573
+ /**
574
+ * Ensure that a mock function is called with specific arguments and called
575
+ * exactly once.
576
+ *
577
+ * @example
578
+ * expect(mockFunc).toHaveBeenCalledExactlyOnceWith('arg1', 42);
579
+ */
580
+ toHaveBeenCalledExactlyOnceWith: <E extends any[]>(...args: E) => void;
581
+ /**
582
+ * This assertion checks if a `Mock` was called before another `Mock`.
583
+ * @param mock - A mock function created by `vi.spyOn` or `vi.fn`
584
+ * @param failIfNoFirstInvocation - Fail if the first mock was never called
585
+ * @example
586
+ * const mock1 = vi.fn()
587
+ * const mock2 = vi.fn()
588
+ *
589
+ * mock1()
590
+ * mock2()
591
+ * mock1()
592
+ *
593
+ * expect(mock1).toHaveBeenCalledBefore(mock2)
594
+ */
595
+ toHaveBeenCalledBefore: (mock: MockInstance, failIfNoFirstInvocation?: boolean) => void;
596
+ /**
597
+ * This assertion checks if a `Mock` was called after another `Mock`.
598
+ * @param mock - A mock function created by `vi.spyOn` or `vi.fn`
599
+ * @param failIfNoFirstInvocation - Fail if the first mock was never called
600
+ * @example
601
+ * const mock1 = vi.fn()
602
+ * const mock2 = vi.fn()
603
+ *
604
+ * mock2()
605
+ * mock1()
606
+ * mock2()
607
+ *
608
+ * expect(mock1).toHaveBeenCalledAfter(mock2)
609
+ */
610
+ toHaveBeenCalledAfter: (mock: MockInstance, failIfNoFirstInvocation?: boolean) => void;
611
+ /**
612
+ * Checks that a promise resolves successfully at least once.
613
+ *
614
+ * @example
615
+ * await expect(promise).toHaveResolved();
616
+ */
617
+ toHaveResolved: () => void;
618
+ /**
619
+ * Checks that a promise resolves to a specific value.
620
+ *
621
+ * @example
622
+ * await expect(promise).toHaveResolvedWith('success');
623
+ */
624
+ toHaveResolvedWith: <E>(value: E) => void;
625
+ /**
626
+ * Ensures a promise resolves a specific number of times.
627
+ *
628
+ * @example
629
+ * expect(mockAsyncFunc).toHaveResolvedTimes(3);
630
+ */
631
+ toHaveResolvedTimes: (times: number) => void;
632
+ /**
633
+ * Asserts that the last resolved value of a promise matches an expected value.
634
+ *
635
+ * @example
636
+ * await expect(mockAsyncFunc).toHaveLastResolvedWith('finalResult');
637
+ */
638
+ toHaveLastResolvedWith: <E>(value: E) => void;
639
+ /**
640
+ * Ensures a specific value was returned by a promise on the nth resolution.
641
+ *
642
+ * @example
643
+ * await expect(mockAsyncFunc).toHaveNthResolvedWith(2, 'secondResult');
644
+ */
645
+ toHaveNthResolvedWith: <E>(nthCall: number, value: E) => void;
646
+ /**
647
+ * Verifies that a promise resolves.
648
+ *
649
+ * @example
650
+ * await expect(someAsyncFunc).resolves.toBe(42);
651
+ */
652
+ resolves: PromisifyAssertion<T>;
653
+ /**
654
+ * Verifies that a promise rejects.
655
+ *
656
+ * @example
657
+ * await expect(someAsyncFunc).rejects.toThrow('error');
658
+ */
659
+ rejects: PromisifyAssertion<T>;
661
660
  }
662
661
  declare global {
663
- namespace jest {
664
- interface Matchers<R, T = {}> {
665
- }
666
- }
662
+ namespace jest {
663
+ interface Matchers<
664
+ R,
665
+ T = {}
666
+ > {}
667
+ }
667
668
  }
668
669
 
669
670
  declare const customMatchers: MatchersObject;
670
671
 
671
672
  interface AsymmetricMatcherInterface {
672
- asymmetricMatch: (other: unknown) => boolean;
673
- toString: () => string;
674
- getExpectedType?: () => string;
675
- toAsymmetricMatcher?: () => string;
673
+ asymmetricMatch: (other: unknown) => boolean;
674
+ toString: () => string;
675
+ getExpectedType?: () => string;
676
+ toAsymmetricMatcher?: () => string;
676
677
  }
677
- declare abstract class AsymmetricMatcher<T, State extends MatcherState = MatcherState> implements AsymmetricMatcherInterface {
678
- protected sample: T;
679
- protected inverse: boolean;
680
- $$typeof: symbol;
681
- constructor(sample: T, inverse?: boolean);
682
- protected getMatcherContext(expect?: Chai.ExpectStatic): State;
683
- abstract asymmetricMatch(other: unknown): boolean;
684
- abstract toString(): string;
685
- getExpectedType?(): string;
686
- toAsymmetricMatcher?(): string;
678
+ declare abstract class AsymmetricMatcher<
679
+ T,
680
+ State extends MatcherState = MatcherState
681
+ > implements AsymmetricMatcherInterface {
682
+ protected sample: T;
683
+ protected inverse: boolean;
684
+ $$typeof: symbol;
685
+ constructor(sample: T, inverse?: boolean);
686
+ protected getMatcherContext(expect?: Chai.ExpectStatic): State;
687
+ abstract asymmetricMatch(other: unknown): boolean;
688
+ abstract toString(): string;
689
+ getExpectedType?(): string;
690
+ toAsymmetricMatcher?(): string;
687
691
  }
688
692
  declare class StringContaining extends AsymmetricMatcher<string> {
689
- constructor(sample: string, inverse?: boolean);
690
- asymmetricMatch(other: string): boolean;
691
- toString(): string;
692
- getExpectedType(): string;
693
+ constructor(sample: string, inverse?: boolean);
694
+ asymmetricMatch(other: string): boolean;
695
+ toString(): string;
696
+ getExpectedType(): string;
693
697
  }
694
698
  declare class Anything extends AsymmetricMatcher<void> {
695
- asymmetricMatch(other: unknown): boolean;
696
- toString(): string;
697
- toAsymmetricMatcher(): string;
699
+ asymmetricMatch(other: unknown): boolean;
700
+ toString(): string;
701
+ toAsymmetricMatcher(): string;
698
702
  }
699
703
  declare class ObjectContaining extends AsymmetricMatcher<Record<string, unknown>> {
700
- constructor(sample: Record<string, unknown>, inverse?: boolean);
701
- getPrototype(obj: object): any;
702
- hasProperty(obj: object | null, property: string): boolean;
703
- asymmetricMatch(other: any): boolean;
704
- toString(): string;
705
- getExpectedType(): string;
704
+ constructor(sample: Record<string, unknown>, inverse?: boolean);
705
+ getPrototype(obj: object): any;
706
+ hasProperty(obj: object | null, property: string): boolean;
707
+ asymmetricMatch(other: any): boolean;
708
+ toString(): string;
709
+ getExpectedType(): string;
706
710
  }
707
711
  declare class ArrayContaining<T = unknown> extends AsymmetricMatcher<Array<T>> {
708
- constructor(sample: Array<T>, inverse?: boolean);
709
- asymmetricMatch(other: Array<T>): boolean;
710
- toString(): string;
711
- getExpectedType(): string;
712
+ constructor(sample: Array<T>, inverse?: boolean);
713
+ asymmetricMatch(other: Array<T>): boolean;
714
+ toString(): string;
715
+ getExpectedType(): string;
712
716
  }
713
717
  declare class Any extends AsymmetricMatcher<any> {
714
- constructor(sample: unknown);
715
- fnNameFor(func: Function): string;
716
- asymmetricMatch(other: unknown): boolean;
717
- toString(): string;
718
- getExpectedType(): string;
719
- toAsymmetricMatcher(): string;
718
+ constructor(sample: unknown);
719
+ fnNameFor(func: Function): string;
720
+ asymmetricMatch(other: unknown): boolean;
721
+ toString(): string;
722
+ getExpectedType(): string;
723
+ toAsymmetricMatcher(): string;
720
724
  }
721
725
  declare class StringMatching extends AsymmetricMatcher<RegExp> {
722
- constructor(sample: string | RegExp, inverse?: boolean);
723
- asymmetricMatch(other: string): boolean;
724
- toString(): string;
725
- getExpectedType(): string;
726
+ constructor(sample: string | RegExp, inverse?: boolean);
727
+ asymmetricMatch(other: string): boolean;
728
+ toString(): string;
729
+ getExpectedType(): string;
726
730
  }
727
731
  declare const JestAsymmetricMatchers: ChaiPlugin;
728
732
 
@@ -747,8 +751,8 @@ declare function generateToBeMessage(deepEqualityName: string, expected?: string
747
751
  declare function pluralize(word: string, count: number): string;
748
752
  declare function getObjectKeys(object: object): Array<string | symbol>;
749
753
  declare function getObjectSubset(object: any, subset: any, customTesters: Array<Tester>): {
750
- subset: any;
751
- stripped: number;
754
+ subset: any
755
+ stripped: number
752
756
  };
753
757
 
754
758
  declare function getState<State extends MatcherState = MatcherState>(expect: ExpectStatic): State;