@vitest/expect 1.1.3 → 1.2.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/dist/index.d.ts +16 -30
- package/dist/index.js +74 -35
- package/package.json +4 -4
package/dist/index.d.ts
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
import * as _vitest_utils from '@vitest/utils';
|
1
2
|
import { stringify, Constructable } from '@vitest/utils';
|
2
3
|
export { setupColors } from '@vitest/utils';
|
3
4
|
import { diff } from '@vitest/utils/diff';
|
@@ -6,35 +7,16 @@ export { DiffOptions } from '@vitest/utils/diff';
|
|
6
7
|
type Formatter = (input: string | number | null | undefined) => string;
|
7
8
|
|
8
9
|
declare function getMatcherUtils(): {
|
9
|
-
EXPECTED_COLOR:
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
RECEIVED_COLOR: {
|
15
|
-
(input: unknown): string;
|
16
|
-
open: string;
|
17
|
-
close: string;
|
18
|
-
};
|
19
|
-
INVERTED_COLOR: {
|
20
|
-
(input: unknown): string;
|
21
|
-
open: string;
|
22
|
-
close: string;
|
23
|
-
};
|
24
|
-
BOLD_WEIGHT: {
|
25
|
-
(input: unknown): string;
|
26
|
-
open: string;
|
27
|
-
close: string;
|
28
|
-
};
|
29
|
-
DIM_COLOR: {
|
30
|
-
(input: unknown): string;
|
31
|
-
open: string;
|
32
|
-
close: string;
|
33
|
-
};
|
10
|
+
EXPECTED_COLOR: _vitest_utils.ColorMethod;
|
11
|
+
RECEIVED_COLOR: _vitest_utils.ColorMethod;
|
12
|
+
INVERTED_COLOR: _vitest_utils.ColorMethod;
|
13
|
+
BOLD_WEIGHT: _vitest_utils.ColorMethod;
|
14
|
+
DIM_COLOR: _vitest_utils.ColorMethod;
|
34
15
|
matcherHint: (matcherName: string, received?: string, expected?: string, options?: MatcherHintOptions) => string;
|
35
16
|
printReceived: (object: unknown) => string;
|
36
17
|
printExpected: (value: unknown) => string;
|
37
18
|
};
|
19
|
+
declare function addCustomEqualityTesters(newTesters: Array<Tester>): void;
|
38
20
|
|
39
21
|
/**
|
40
22
|
* Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
|
@@ -45,7 +27,10 @@ declare function getMatcherUtils(): {
|
|
45
27
|
*/
|
46
28
|
|
47
29
|
type ChaiPlugin = Chai.ChaiPlugin;
|
48
|
-
type Tester = (a: any, b: any) => boolean | undefined;
|
30
|
+
type Tester = (this: TesterContext, a: any, b: any, customTesters: Array<Tester>) => boolean | undefined;
|
31
|
+
interface TesterContext {
|
32
|
+
equals: (a: unknown, b: unknown, customTesters?: Array<Tester>, strictCheck?: boolean) => boolean;
|
33
|
+
}
|
49
34
|
|
50
35
|
interface MatcherHintOptions {
|
51
36
|
comment?: string;
|
@@ -98,6 +83,7 @@ interface ExpectStatic extends Chai.ExpectStatic, AsymmetricMatchersContaining {
|
|
98
83
|
unreachable(message?: string): never;
|
99
84
|
soft<T>(actual: T, message?: string): Assertion<T>;
|
100
85
|
extend(expects: MatchersObject): void;
|
86
|
+
addEqualityTesters(testers: Array<Tester>): void;
|
101
87
|
assertions(expected: number): void;
|
102
88
|
hasAssertions(): void;
|
103
89
|
anything(): any;
|
@@ -244,11 +230,11 @@ declare function fnNameFor(func: Function): string;
|
|
244
230
|
declare function hasProperty(obj: object | null, property: string): boolean;
|
245
231
|
declare function isImmutableUnorderedKeyed(maybeKeyed: any): boolean;
|
246
232
|
declare function isImmutableUnorderedSet(maybeSet: any): boolean;
|
247
|
-
declare function iterableEquality(a: any, b: any, aStack?: Array<any>, bStack?: Array<any>): boolean | undefined;
|
248
|
-
declare function subsetEquality(object: unknown, subset: unknown): boolean | undefined;
|
233
|
+
declare function iterableEquality(a: any, b: any, customTesters?: Array<Tester>, aStack?: Array<any>, bStack?: Array<any>): boolean | undefined;
|
234
|
+
declare function subsetEquality(object: unknown, subset: unknown, customTesters?: Array<Tester>): boolean | undefined;
|
249
235
|
declare function typeEquality(a: any, b: any): boolean | undefined;
|
250
236
|
declare function arrayBufferEquality(a: unknown, b: unknown): boolean | undefined;
|
251
|
-
declare function sparseArrayEquality(a: unknown, b: unknown): boolean | undefined;
|
237
|
+
declare function sparseArrayEquality(a: unknown, b: unknown, customTesters?: Array<Tester>): boolean | undefined;
|
252
238
|
declare function generateToBeMessage(deepEqualityName: string, expected?: string, actual?: string): string;
|
253
239
|
declare function pluralize(word: string, count: number): string;
|
254
240
|
|
@@ -264,4 +250,4 @@ declare const JestChaiExpect: ChaiPlugin;
|
|
264
250
|
|
265
251
|
declare const JestExtend: ChaiPlugin;
|
266
252
|
|
267
|
-
export { ASYMMETRIC_MATCHERS_OBJECT, Any, Anything, ArrayContaining, type Assertion, AsymmetricMatcher, type AsymmetricMatcherInterface, type AsymmetricMatchersContaining, type AsyncExpectationResult, type ChaiPlugin, type ExpectStatic, type ExpectationResult, GLOBAL_EXPECT, JEST_MATCHERS_OBJECT, type JestAssertion, JestAsymmetricMatchers, JestChaiExpect, JestExtend, MATCHERS_OBJECT, type MatcherHintOptions, type MatcherState, type MatchersObject, ObjectContaining, type RawMatcherFn, StringContaining, StringMatching, type SyncExpectationResult, type Tester, arrayBufferEquality, equals, fnNameFor, generateToBeMessage, getState, hasAsymmetric, hasProperty, isA, isAsymmetric, isImmutableUnorderedKeyed, isImmutableUnorderedSet, iterableEquality, pluralize, setState, sparseArrayEquality, subsetEquality, typeEquality };
|
253
|
+
export { ASYMMETRIC_MATCHERS_OBJECT, Any, Anything, ArrayContaining, type Assertion, AsymmetricMatcher, type AsymmetricMatcherInterface, type AsymmetricMatchersContaining, type AsyncExpectationResult, type ChaiPlugin, type ExpectStatic, type ExpectationResult, GLOBAL_EXPECT, JEST_MATCHERS_OBJECT, type JestAssertion, JestAsymmetricMatchers, JestChaiExpect, JestExtend, MATCHERS_OBJECT, type MatcherHintOptions, type MatcherState, type MatchersObject, ObjectContaining, type RawMatcherFn, StringContaining, StringMatching, type SyncExpectationResult, type Tester, type TesterContext, addCustomEqualityTesters, arrayBufferEquality, equals, fnNameFor, generateToBeMessage, getState, hasAsymmetric, hasProperty, isA, isAsymmetric, isImmutableUnorderedKeyed, isImmutableUnorderedSet, iterableEquality, pluralize, setState, sparseArrayEquality, subsetEquality, typeEquality };
|
package/dist/index.js
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
import { getColors, stringify, isObject, assertTypes } from '@vitest/utils';
|
1
|
+
import { getType, getColors, stringify, isObject, assertTypes } from '@vitest/utils';
|
2
2
|
export { setupColors } from '@vitest/utils';
|
3
3
|
import { diff } from '@vitest/utils/diff';
|
4
4
|
import { isMockFunction } from '@vitest/spy';
|
@@ -13,6 +13,7 @@ const ASYMMETRIC_MATCHERS_OBJECT = Symbol.for("asymmetric-matchers-object");
|
|
13
13
|
if (!Object.prototype.hasOwnProperty.call(globalThis, MATCHERS_OBJECT)) {
|
14
14
|
const globalState = /* @__PURE__ */ new WeakMap();
|
15
15
|
const matchers = /* @__PURE__ */ Object.create(null);
|
16
|
+
const customEqualityTesters = [];
|
16
17
|
const assymetricMatchers = /* @__PURE__ */ Object.create(null);
|
17
18
|
Object.defineProperty(globalThis, MATCHERS_OBJECT, {
|
18
19
|
get: () => globalState
|
@@ -21,7 +22,8 @@ if (!Object.prototype.hasOwnProperty.call(globalThis, MATCHERS_OBJECT)) {
|
|
21
22
|
configurable: true,
|
22
23
|
get: () => ({
|
23
24
|
state: globalState.get(globalThis[GLOBAL_EXPECT]),
|
24
|
-
matchers
|
25
|
+
matchers,
|
26
|
+
customEqualityTesters
|
25
27
|
})
|
26
28
|
});
|
27
29
|
Object.defineProperty(globalThis, ASYMMETRIC_MATCHERS_OBJECT, {
|
@@ -106,6 +108,21 @@ function getMatcherUtils() {
|
|
106
108
|
printExpected
|
107
109
|
};
|
108
110
|
}
|
111
|
+
function addCustomEqualityTesters(newTesters) {
|
112
|
+
if (!Array.isArray(newTesters)) {
|
113
|
+
throw new TypeError(
|
114
|
+
`expect.customEqualityTesters: Must be set to an array of Testers. Was given "${getType(
|
115
|
+
newTesters
|
116
|
+
)}"`
|
117
|
+
);
|
118
|
+
}
|
119
|
+
globalThis[JEST_MATCHERS_OBJECT].customEqualityTesters.push(
|
120
|
+
...newTesters
|
121
|
+
);
|
122
|
+
}
|
123
|
+
function getCustomEqualityTesters() {
|
124
|
+
return globalThis[JEST_MATCHERS_OBJECT].customEqualityTesters;
|
125
|
+
}
|
109
126
|
|
110
127
|
function equals(a, b, customTesters, strictCheck) {
|
111
128
|
customTesters = customTesters || [];
|
@@ -144,8 +161,9 @@ function eq(a, b, aStack, bStack, customTesters, hasKey2) {
|
|
144
161
|
const asymmetricResult = asymmetricMatch(a, b);
|
145
162
|
if (asymmetricResult !== void 0)
|
146
163
|
return asymmetricResult;
|
164
|
+
const testerContext = { equals };
|
147
165
|
for (let i = 0; i < customTesters.length; i++) {
|
148
|
-
const customTesterResult = customTesters[i](a, b);
|
166
|
+
const customTesterResult = customTesters[i].call(testerContext, a, b, customTesters);
|
149
167
|
if (customTesterResult !== void 0)
|
150
168
|
return customTesterResult;
|
151
169
|
}
|
@@ -266,7 +284,7 @@ const IteratorSymbol = Symbol.iterator;
|
|
266
284
|
function hasIterator(object) {
|
267
285
|
return !!(object != null && object[IteratorSymbol]);
|
268
286
|
}
|
269
|
-
function iterableEquality(a, b, aStack = [], bStack = []) {
|
287
|
+
function iterableEquality(a, b, customTesters = [], aStack = [], bStack = []) {
|
270
288
|
if (typeof a !== "object" || typeof b !== "object" || Array.isArray(a) || Array.isArray(b) || !hasIterator(a) || !hasIterator(b))
|
271
289
|
return void 0;
|
272
290
|
if (a.constructor !== b.constructor)
|
@@ -278,7 +296,19 @@ function iterableEquality(a, b, aStack = [], bStack = []) {
|
|
278
296
|
}
|
279
297
|
aStack.push(a);
|
280
298
|
bStack.push(b);
|
281
|
-
const
|
299
|
+
const filteredCustomTesters = [
|
300
|
+
...customTesters.filter((t) => t !== iterableEquality),
|
301
|
+
iterableEqualityWithStack
|
302
|
+
];
|
303
|
+
function iterableEqualityWithStack(a2, b2) {
|
304
|
+
return iterableEquality(
|
305
|
+
a2,
|
306
|
+
b2,
|
307
|
+
[...filteredCustomTesters],
|
308
|
+
[...aStack],
|
309
|
+
[...bStack]
|
310
|
+
);
|
311
|
+
}
|
282
312
|
if (a.size !== void 0) {
|
283
313
|
if (a.size !== b.size) {
|
284
314
|
return false;
|
@@ -288,7 +318,7 @@ function iterableEquality(a, b, aStack = [], bStack = []) {
|
|
288
318
|
if (!b.has(aValue)) {
|
289
319
|
let has = false;
|
290
320
|
for (const bValue of b) {
|
291
|
-
const isEqual = equals(aValue, bValue,
|
321
|
+
const isEqual = equals(aValue, bValue, filteredCustomTesters);
|
292
322
|
if (isEqual === true)
|
293
323
|
has = true;
|
294
324
|
}
|
@@ -304,18 +334,13 @@ function iterableEquality(a, b, aStack = [], bStack = []) {
|
|
304
334
|
} else if (isA("Map", a) || isImmutableUnorderedKeyed(a)) {
|
305
335
|
let allFound = true;
|
306
336
|
for (const aEntry of a) {
|
307
|
-
if (!b.has(aEntry[0]) || !equals(aEntry[1], b.get(aEntry[0]),
|
337
|
+
if (!b.has(aEntry[0]) || !equals(aEntry[1], b.get(aEntry[0]), filteredCustomTesters)) {
|
308
338
|
let has = false;
|
309
339
|
for (const bEntry of b) {
|
310
|
-
const matchedKey = equals(aEntry[0], bEntry[0],
|
311
|
-
iterableEqualityWithStack
|
312
|
-
]);
|
340
|
+
const matchedKey = equals(aEntry[0], bEntry[0], filteredCustomTesters);
|
313
341
|
let matchedValue = false;
|
314
|
-
if (matchedKey === true)
|
315
|
-
matchedValue = equals(aEntry[1], bEntry[1],
|
316
|
-
iterableEqualityWithStack
|
317
|
-
]);
|
318
|
-
}
|
342
|
+
if (matchedKey === true)
|
343
|
+
matchedValue = equals(aEntry[1], bEntry[1], filteredCustomTesters);
|
319
344
|
if (matchedValue === true)
|
320
345
|
has = true;
|
321
346
|
}
|
@@ -333,7 +358,7 @@ function iterableEquality(a, b, aStack = [], bStack = []) {
|
|
333
358
|
const bIterator = b[IteratorSymbol]();
|
334
359
|
for (const aValue of a) {
|
335
360
|
const nextB = bIterator.next();
|
336
|
-
if (nextB.done || !equals(aValue, nextB.value,
|
361
|
+
if (nextB.done || !equals(aValue, nextB.value, filteredCustomTesters))
|
337
362
|
return false;
|
338
363
|
}
|
339
364
|
if (!bIterator.next().done)
|
@@ -351,18 +376,19 @@ function hasPropertyInObject(object, key) {
|
|
351
376
|
function isObjectWithKeys(a) {
|
352
377
|
return isObject(a) && !(a instanceof Error) && !Array.isArray(a) && !(a instanceof Date);
|
353
378
|
}
|
354
|
-
function subsetEquality(object, subset) {
|
379
|
+
function subsetEquality(object, subset, customTesters = []) {
|
380
|
+
const filteredCustomTesters = customTesters.filter((t) => t !== subsetEquality);
|
355
381
|
const subsetEqualityWithContext = (seenReferences = /* @__PURE__ */ new WeakMap()) => (object2, subset2) => {
|
356
382
|
if (!isObjectWithKeys(subset2))
|
357
383
|
return void 0;
|
358
384
|
return Object.keys(subset2).every((key) => {
|
359
385
|
if (isObjectWithKeys(subset2[key])) {
|
360
386
|
if (seenReferences.has(subset2[key]))
|
361
|
-
return equals(object2[key], subset2[key],
|
387
|
+
return equals(object2[key], subset2[key], filteredCustomTesters);
|
362
388
|
seenReferences.set(subset2[key], true);
|
363
389
|
}
|
364
390
|
const result = object2 != null && hasPropertyInObject(object2, key) && equals(object2[key], subset2[key], [
|
365
|
-
|
391
|
+
...filteredCustomTesters,
|
366
392
|
subsetEqualityWithContext(seenReferences)
|
367
393
|
]);
|
368
394
|
seenReferences.delete(subset2[key]);
|
@@ -397,12 +423,13 @@ function arrayBufferEquality(a, b) {
|
|
397
423
|
}
|
398
424
|
return true;
|
399
425
|
}
|
400
|
-
function sparseArrayEquality(a, b) {
|
426
|
+
function sparseArrayEquality(a, b, customTesters = []) {
|
401
427
|
if (!Array.isArray(a) || !Array.isArray(b))
|
402
428
|
return void 0;
|
403
429
|
const aKeys = Object.keys(a);
|
404
430
|
const bKeys = Object.keys(b);
|
405
|
-
|
431
|
+
const filteredCustomTesters = customTesters.filter((t) => t !== sparseArrayEquality);
|
432
|
+
return equals(a, b, filteredCustomTesters, true) && equals(aKeys, bKeys);
|
406
433
|
}
|
407
434
|
function generateToBeMessage(deepEqualityName, expected = "#{this}", actual = "#{exp}") {
|
408
435
|
const toBeMessage = `expected ${expected} to be ${actual} // Object.is equality`;
|
@@ -432,7 +459,7 @@ class AsymmetricMatcher {
|
|
432
459
|
...getState(expect || globalThis[GLOBAL_EXPECT]),
|
433
460
|
equals,
|
434
461
|
isNot: this.inverse,
|
435
|
-
customTesters:
|
462
|
+
customTesters: getCustomEqualityTesters(),
|
436
463
|
utils: {
|
437
464
|
...getMatcherUtils(),
|
438
465
|
diff,
|
@@ -442,6 +469,14 @@ class AsymmetricMatcher {
|
|
442
469
|
}
|
443
470
|
};
|
444
471
|
}
|
472
|
+
// implement custom chai/loupe inspect for better AssertionError.message formatting
|
473
|
+
// https://github.com/chaijs/loupe/blob/9b8a6deabcd50adc056a64fb705896194710c5c6/src/index.ts#L29
|
474
|
+
[Symbol.for("chai/inspect")](options) {
|
475
|
+
const result = stringify(this, options.depth, { min: true });
|
476
|
+
if (result.length <= options.truncate)
|
477
|
+
return result;
|
478
|
+
return `${this.toString()}{\u2026}`;
|
479
|
+
}
|
445
480
|
}
|
446
481
|
class StringContaining extends AsymmetricMatcher {
|
447
482
|
constructor(sample, inverse = false) {
|
@@ -496,8 +531,9 @@ class ObjectContaining extends AsymmetricMatcher {
|
|
496
531
|
);
|
497
532
|
}
|
498
533
|
let result = true;
|
534
|
+
const matcherContext = this.getMatcherContext();
|
499
535
|
for (const property in this.sample) {
|
500
|
-
if (!this.hasProperty(other, property) || !equals(this.sample[property], other[property])) {
|
536
|
+
if (!this.hasProperty(other, property) || !equals(this.sample[property], other[property], matcherContext.customTesters)) {
|
501
537
|
result = false;
|
502
538
|
break;
|
503
539
|
}
|
@@ -521,8 +557,9 @@ class ArrayContaining extends AsymmetricMatcher {
|
|
521
557
|
`You must provide an array to ${this.toString()}, not '${typeof this.sample}'.`
|
522
558
|
);
|
523
559
|
}
|
560
|
+
const matcherContext = this.getMatcherContext();
|
524
561
|
const result = this.sample.length === 0 || Array.isArray(other) && this.sample.every(
|
525
|
-
(item) => other.some((another) => equals(item, another))
|
562
|
+
(item) => other.some((another) => equals(item, another, matcherContext.customTesters))
|
526
563
|
);
|
527
564
|
return this.inverse ? !result : result;
|
528
565
|
}
|
@@ -722,6 +759,7 @@ function wrapSoft(utils, fn) {
|
|
722
759
|
const JestChaiExpect = (chai, utils) => {
|
723
760
|
const { AssertionError } = chai;
|
724
761
|
const c = () => getColors();
|
762
|
+
const customTesters = getCustomEqualityTesters();
|
725
763
|
function def(name, fn) {
|
726
764
|
const addMethod = (n) => {
|
727
765
|
const softWrapper = wrapSoft(utils, fn);
|
@@ -767,7 +805,7 @@ const JestChaiExpect = (chai, utils) => {
|
|
767
805
|
const equal = equals(
|
768
806
|
actual,
|
769
807
|
expected,
|
770
|
-
[iterableEquality]
|
808
|
+
[...customTesters, iterableEquality]
|
771
809
|
);
|
772
810
|
return this.assert(
|
773
811
|
equal,
|
@@ -783,6 +821,7 @@ const JestChaiExpect = (chai, utils) => {
|
|
783
821
|
obj,
|
784
822
|
expected,
|
785
823
|
[
|
824
|
+
...customTesters,
|
786
825
|
iterableEquality,
|
787
826
|
typeEquality,
|
788
827
|
sparseArrayEquality,
|
@@ -807,6 +846,7 @@ const JestChaiExpect = (chai, utils) => {
|
|
807
846
|
actual,
|
808
847
|
expected,
|
809
848
|
[
|
849
|
+
...customTesters,
|
810
850
|
iterableEquality,
|
811
851
|
typeEquality,
|
812
852
|
sparseArrayEquality,
|
@@ -820,7 +860,7 @@ const JestChaiExpect = (chai, utils) => {
|
|
820
860
|
const toEqualPass = equals(
|
821
861
|
actual,
|
822
862
|
expected,
|
823
|
-
[iterableEquality]
|
863
|
+
[...customTesters, iterableEquality]
|
824
864
|
);
|
825
865
|
if (toEqualPass)
|
826
866
|
deepEqualityName = "toEqual";
|
@@ -837,7 +877,7 @@ const JestChaiExpect = (chai, utils) => {
|
|
837
877
|
def("toMatchObject", function(expected) {
|
838
878
|
const actual = this._obj;
|
839
879
|
return this.assert(
|
840
|
-
equals(actual, expected, [iterableEquality, subsetEquality]),
|
880
|
+
equals(actual, expected, [...customTesters, iterableEquality, subsetEquality]),
|
841
881
|
"expected #{this} to match object #{exp}",
|
842
882
|
"expected #{this} to not match object #{exp}",
|
843
883
|
expected,
|
@@ -882,7 +922,7 @@ const JestChaiExpect = (chai, utils) => {
|
|
882
922
|
def("toContainEqual", function(expected) {
|
883
923
|
const obj = utils.flag(this, "object");
|
884
924
|
const index = Array.from(obj).findIndex((item) => {
|
885
|
-
return equals(item, expected);
|
925
|
+
return equals(item, expected, customTesters);
|
886
926
|
});
|
887
927
|
this.assert(
|
888
928
|
index !== -1,
|
@@ -1008,7 +1048,7 @@ const JestChaiExpect = (chai, utils) => {
|
|
1008
1048
|
return utils.getPathInfo(actual, propertyName);
|
1009
1049
|
};
|
1010
1050
|
const { value, exists } = getValue();
|
1011
|
-
const pass = exists && (args.length === 1 || equals(expected, value));
|
1051
|
+
const pass = exists && (args.length === 1 || equals(expected, value, customTesters));
|
1012
1052
|
const valueString = args.length === 1 ? "" : ` with value ${utils.objDisplay(expected)}`;
|
1013
1053
|
return this.assert(
|
1014
1054
|
pass,
|
@@ -1156,7 +1196,7 @@ Number of calls: ${c().bold(spy.mock.calls.length)}
|
|
1156
1196
|
def(["toHaveBeenCalledWith", "toBeCalledWith"], function(...args) {
|
1157
1197
|
const spy = getSpy(this);
|
1158
1198
|
const spyName = spy.getMockName();
|
1159
|
-
const pass = spy.mock.calls.some((callArg) => equals(callArg, args, [iterableEquality]));
|
1199
|
+
const pass = spy.mock.calls.some((callArg) => equals(callArg, args, [...customTesters, iterableEquality]));
|
1160
1200
|
const isNot = utils.flag(this, "negate");
|
1161
1201
|
const msg = utils.getMessage(
|
1162
1202
|
this,
|
@@ -1175,7 +1215,7 @@ Number of calls: ${c().bold(spy.mock.calls.length)}
|
|
1175
1215
|
const spyName = spy.getMockName();
|
1176
1216
|
const nthCall = spy.mock.calls[times - 1];
|
1177
1217
|
this.assert(
|
1178
|
-
equals(nthCall, args, [iterableEquality]),
|
1218
|
+
equals(nthCall, args, [...customTesters, iterableEquality]),
|
1179
1219
|
`expected ${ordinalOf(times)} "${spyName}" call to have been called with #{exp}`,
|
1180
1220
|
`expected ${ordinalOf(times)} "${spyName}" call to not have been called with #{exp}`,
|
1181
1221
|
args,
|
@@ -1187,7 +1227,7 @@ Number of calls: ${c().bold(spy.mock.calls.length)}
|
|
1187
1227
|
const spyName = spy.getMockName();
|
1188
1228
|
const lastCall = spy.mock.calls[spy.mock.calls.length - 1];
|
1189
1229
|
this.assert(
|
1190
|
-
equals(lastCall, args, [iterableEquality]),
|
1230
|
+
equals(lastCall, args, [...customTesters, iterableEquality]),
|
1191
1231
|
`expected last "${spyName}" call to have been called with #{exp}`,
|
1192
1232
|
`expected last "${spyName}" call to not have been called with #{exp}`,
|
1193
1233
|
args,
|
@@ -1423,8 +1463,7 @@ function getMatcherState(assertion, expect) {
|
|
1423
1463
|
};
|
1424
1464
|
const matcherState = {
|
1425
1465
|
...getState(expect),
|
1426
|
-
|
1427
|
-
customTesters: [],
|
1466
|
+
customTesters: getCustomEqualityTesters(),
|
1428
1467
|
isNot,
|
1429
1468
|
utils: jestUtils,
|
1430
1469
|
promise,
|
@@ -1514,4 +1553,4 @@ const JestExtend = (chai, utils) => {
|
|
1514
1553
|
});
|
1515
1554
|
};
|
1516
1555
|
|
1517
|
-
export { ASYMMETRIC_MATCHERS_OBJECT, Any, Anything, ArrayContaining, AsymmetricMatcher, GLOBAL_EXPECT, JEST_MATCHERS_OBJECT, JestAsymmetricMatchers, JestChaiExpect, JestExtend, MATCHERS_OBJECT, ObjectContaining, StringContaining, StringMatching, arrayBufferEquality, equals, fnNameFor, generateToBeMessage, getState, hasAsymmetric, hasProperty, isA, isAsymmetric, isImmutableUnorderedKeyed, isImmutableUnorderedSet, iterableEquality, pluralize, setState, sparseArrayEquality, subsetEquality, typeEquality };
|
1556
|
+
export { ASYMMETRIC_MATCHERS_OBJECT, Any, Anything, ArrayContaining, AsymmetricMatcher, GLOBAL_EXPECT, JEST_MATCHERS_OBJECT, JestAsymmetricMatchers, JestChaiExpect, JestExtend, MATCHERS_OBJECT, ObjectContaining, StringContaining, StringMatching, addCustomEqualityTesters, arrayBufferEquality, equals, fnNameFor, generateToBeMessage, getState, hasAsymmetric, hasProperty, isA, isAsymmetric, isImmutableUnorderedKeyed, isImmutableUnorderedSet, iterableEquality, pluralize, setState, sparseArrayEquality, subsetEquality, typeEquality };
|
package/package.json
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
{
|
2
2
|
"name": "@vitest/expect",
|
3
3
|
"type": "module",
|
4
|
-
"version": "1.1
|
4
|
+
"version": "1.2.1",
|
5
5
|
"description": "Jest's expect matchers as a Chai plugin",
|
6
6
|
"license": "MIT",
|
7
7
|
"funding": "https://opencollective.com/vitest",
|
@@ -31,14 +31,14 @@
|
|
31
31
|
],
|
32
32
|
"dependencies": {
|
33
33
|
"chai": "^4.3.10",
|
34
|
-
"@vitest/spy": "1.1
|
35
|
-
"@vitest/utils": "1.1
|
34
|
+
"@vitest/spy": "1.2.1",
|
35
|
+
"@vitest/utils": "1.2.1"
|
36
36
|
},
|
37
37
|
"devDependencies": {
|
38
38
|
"@types/chai": "4.3.6",
|
39
39
|
"picocolors": "^1.0.0",
|
40
40
|
"rollup-plugin-copy": "^3.5.0",
|
41
|
-
"@vitest/runner": "1.1
|
41
|
+
"@vitest/runner": "1.2.1"
|
42
42
|
},
|
43
43
|
"scripts": {
|
44
44
|
"build": "rimraf dist && rollup -c",
|