@vitest/expect 3.1.3 → 3.2.0-beta.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +70 -69
- package/dist/index.js +1 -1
- package/package.json +5 -5
- package/dist/chai.d.cts +0 -2125
package/dist/index.d.ts
CHANGED
@@ -9,6 +9,67 @@ declare const JEST_MATCHERS_OBJECT: unique symbol;
|
|
9
9
|
declare const GLOBAL_EXPECT: unique symbol;
|
10
10
|
declare const ASYMMETRIC_MATCHERS_OBJECT: unique symbol;
|
11
11
|
|
12
|
+
interface AsymmetricMatcherInterface {
|
13
|
+
asymmetricMatch: (other: unknown) => boolean;
|
14
|
+
toString: () => string;
|
15
|
+
getExpectedType?: () => string;
|
16
|
+
toAsymmetricMatcher?: () => string;
|
17
|
+
}
|
18
|
+
declare abstract class AsymmetricMatcher<
|
19
|
+
T,
|
20
|
+
State extends MatcherState = MatcherState
|
21
|
+
> implements AsymmetricMatcherInterface {
|
22
|
+
protected sample: T;
|
23
|
+
protected inverse: boolean;
|
24
|
+
$$typeof: symbol;
|
25
|
+
constructor(sample: T, inverse?: boolean);
|
26
|
+
protected getMatcherContext(expect?: Chai.ExpectStatic): State;
|
27
|
+
abstract asymmetricMatch(other: unknown): boolean;
|
28
|
+
abstract toString(): string;
|
29
|
+
getExpectedType?(): string;
|
30
|
+
toAsymmetricMatcher?(): string;
|
31
|
+
}
|
32
|
+
declare class StringContaining extends AsymmetricMatcher<string> {
|
33
|
+
constructor(sample: string, inverse?: boolean);
|
34
|
+
asymmetricMatch(other: string): boolean;
|
35
|
+
toString(): string;
|
36
|
+
getExpectedType(): string;
|
37
|
+
}
|
38
|
+
declare class Anything extends AsymmetricMatcher<void> {
|
39
|
+
asymmetricMatch(other: unknown): boolean;
|
40
|
+
toString(): string;
|
41
|
+
toAsymmetricMatcher(): string;
|
42
|
+
}
|
43
|
+
declare class ObjectContaining extends AsymmetricMatcher<Record<string, unknown>> {
|
44
|
+
constructor(sample: Record<string, unknown>, inverse?: boolean);
|
45
|
+
getPrototype(obj: object): any;
|
46
|
+
hasProperty(obj: object | null, property: string): boolean;
|
47
|
+
asymmetricMatch(other: any): boolean;
|
48
|
+
toString(): string;
|
49
|
+
getExpectedType(): string;
|
50
|
+
}
|
51
|
+
declare class ArrayContaining<T = unknown> extends AsymmetricMatcher<Array<T>> {
|
52
|
+
constructor(sample: Array<T>, inverse?: boolean);
|
53
|
+
asymmetricMatch(other: Array<T>): boolean;
|
54
|
+
toString(): string;
|
55
|
+
getExpectedType(): string;
|
56
|
+
}
|
57
|
+
declare class Any extends AsymmetricMatcher<any> {
|
58
|
+
constructor(sample: unknown);
|
59
|
+
fnNameFor(func: Function): string;
|
60
|
+
asymmetricMatch(other: unknown): boolean;
|
61
|
+
toString(): string;
|
62
|
+
getExpectedType(): string;
|
63
|
+
toAsymmetricMatcher(): string;
|
64
|
+
}
|
65
|
+
declare class StringMatching extends AsymmetricMatcher<RegExp> {
|
66
|
+
constructor(sample: string | RegExp, inverse?: boolean);
|
67
|
+
asymmetricMatch(other: string): boolean;
|
68
|
+
toString(): string;
|
69
|
+
getExpectedType(): string;
|
70
|
+
}
|
71
|
+
declare const JestAsymmetricMatchers: ChaiPlugin;
|
72
|
+
|
12
73
|
declare function matcherHint(matcherName: string, received?: string, expected?: string, options?: MatcherHintOptions): string;
|
13
74
|
declare function printReceived(object: unknown): string;
|
14
75
|
declare function printExpected(value: unknown): string;
|
@@ -92,8 +153,8 @@ type MatchersObject<T extends MatcherState = MatcherState> = Record<string, RawM
|
|
92
153
|
interface ExpectStatic extends Chai.ExpectStatic, AsymmetricMatchersContaining {
|
93
154
|
<T>(actual: T, message?: string): Assertion<T>;
|
94
155
|
extend: (expects: MatchersObject) => void;
|
95
|
-
anything: () =>
|
96
|
-
any: (constructor: unknown) =>
|
156
|
+
anything: () => AsymmetricMatcher<unknown>;
|
157
|
+
any: (constructor: unknown) => AsymmetricMatcher<unknown>;
|
97
158
|
getState: () => MatcherState;
|
98
159
|
setState: (state: Partial<MatcherState>) => void;
|
99
160
|
not: AsymmetricMatchersContaining;
|
@@ -135,14 +196,14 @@ interface AsymmetricMatchersContaining extends CustomMatcher {
|
|
135
196
|
* @example
|
136
197
|
* expect({ a: '1', b: 2 }).toEqual(expect.objectContaining({ a: '1' }))
|
137
198
|
*/
|
138
|
-
objectContaining: <T = any>(expected: T) => any;
|
199
|
+
objectContaining: <T = any>(expected: DeeplyAllowMatchers<T>) => any;
|
139
200
|
/**
|
140
201
|
* Matches if the received array contains all elements in the expected array.
|
141
202
|
*
|
142
203
|
* @example
|
143
204
|
* expect(['a', 'b', 'c']).toEqual(expect.arrayContaining(['b', 'a']));
|
144
205
|
*/
|
145
|
-
arrayContaining: <T = unknown>(expected: Array<T
|
206
|
+
arrayContaining: <T = unknown>(expected: Array<DeeplyAllowMatchers<T>>) => any;
|
146
207
|
/**
|
147
208
|
* Matches if the received string or regex matches the expected pattern.
|
148
209
|
*
|
@@ -162,6 +223,7 @@ interface AsymmetricMatchersContaining extends CustomMatcher {
|
|
162
223
|
*/
|
163
224
|
closeTo: (expected: number, precision?: number) => any;
|
164
225
|
}
|
226
|
+
type DeeplyAllowMatchers<T> = T extends Array<infer Element> ? (DeeplyAllowMatchers<Element> | Element)[] : T extends object ? { [K in keyof T] : DeeplyAllowMatchers<T[K]> | AsymmetricMatcher<unknown> } : T;
|
165
227
|
interface JestAssertion<T = any> extends jest.Matchers<void, T>, CustomMatcher {
|
166
228
|
/**
|
167
229
|
* Used when you want to check that two objects have the same value.
|
@@ -170,14 +232,14 @@ interface JestAssertion<T = any> extends jest.Matchers<void, T>, CustomMatcher {
|
|
170
232
|
* @example
|
171
233
|
* expect(user).toEqual({ name: 'Alice', age: 30 });
|
172
234
|
*/
|
173
|
-
toEqual: <E>(expected: E) => void;
|
235
|
+
toEqual: <E>(expected: DeeplyAllowMatchers<E>) => void;
|
174
236
|
/**
|
175
237
|
* Use to test that objects have the same types as well as structure.
|
176
238
|
*
|
177
239
|
* @example
|
178
240
|
* expect(user).toStrictEqual({ name: 'Alice', age: 30 });
|
179
241
|
*/
|
180
|
-
toStrictEqual: <E>(expected: E) => void;
|
242
|
+
toStrictEqual: <E>(expected: DeeplyAllowMatchers<E>) => void;
|
181
243
|
/**
|
182
244
|
* Checks that a value is what you expect. It calls `Object.is` to compare values.
|
183
245
|
* Don't use `toBe` with floating-point numbers.
|
@@ -204,7 +266,7 @@ interface JestAssertion<T = any> extends jest.Matchers<void, T>, CustomMatcher {
|
|
204
266
|
* address: { city: 'Wonderland' }
|
205
267
|
* });
|
206
268
|
*/
|
207
|
-
toMatchObject: <E extends object | any[]>(expected: E) => void;
|
269
|
+
toMatchObject: <E extends object | any[]>(expected: DeeplyAllowMatchers<E>) => void;
|
208
270
|
/**
|
209
271
|
* Used when you want to check that an item is in a list.
|
210
272
|
* For testing the items in the list, this uses `===`, a strict equality check.
|
@@ -671,67 +733,6 @@ declare global {
|
|
671
733
|
|
672
734
|
declare const customMatchers: MatchersObject;
|
673
735
|
|
674
|
-
interface AsymmetricMatcherInterface {
|
675
|
-
asymmetricMatch: (other: unknown) => boolean;
|
676
|
-
toString: () => string;
|
677
|
-
getExpectedType?: () => string;
|
678
|
-
toAsymmetricMatcher?: () => string;
|
679
|
-
}
|
680
|
-
declare abstract class AsymmetricMatcher<
|
681
|
-
T,
|
682
|
-
State extends MatcherState = MatcherState
|
683
|
-
> implements AsymmetricMatcherInterface {
|
684
|
-
protected sample: T;
|
685
|
-
protected inverse: boolean;
|
686
|
-
$$typeof: symbol;
|
687
|
-
constructor(sample: T, inverse?: boolean);
|
688
|
-
protected getMatcherContext(expect?: Chai.ExpectStatic): State;
|
689
|
-
abstract asymmetricMatch(other: unknown): boolean;
|
690
|
-
abstract toString(): string;
|
691
|
-
getExpectedType?(): string;
|
692
|
-
toAsymmetricMatcher?(): string;
|
693
|
-
}
|
694
|
-
declare class StringContaining extends AsymmetricMatcher<string> {
|
695
|
-
constructor(sample: string, inverse?: boolean);
|
696
|
-
asymmetricMatch(other: string): boolean;
|
697
|
-
toString(): string;
|
698
|
-
getExpectedType(): string;
|
699
|
-
}
|
700
|
-
declare class Anything extends AsymmetricMatcher<void> {
|
701
|
-
asymmetricMatch(other: unknown): boolean;
|
702
|
-
toString(): string;
|
703
|
-
toAsymmetricMatcher(): string;
|
704
|
-
}
|
705
|
-
declare class ObjectContaining extends AsymmetricMatcher<Record<string, unknown>> {
|
706
|
-
constructor(sample: Record<string, unknown>, inverse?: boolean);
|
707
|
-
getPrototype(obj: object): any;
|
708
|
-
hasProperty(obj: object | null, property: string): boolean;
|
709
|
-
asymmetricMatch(other: any): boolean;
|
710
|
-
toString(): string;
|
711
|
-
getExpectedType(): string;
|
712
|
-
}
|
713
|
-
declare class ArrayContaining<T = unknown> extends AsymmetricMatcher<Array<T>> {
|
714
|
-
constructor(sample: Array<T>, inverse?: boolean);
|
715
|
-
asymmetricMatch(other: Array<T>): boolean;
|
716
|
-
toString(): string;
|
717
|
-
getExpectedType(): string;
|
718
|
-
}
|
719
|
-
declare class Any extends AsymmetricMatcher<any> {
|
720
|
-
constructor(sample: unknown);
|
721
|
-
fnNameFor(func: Function): string;
|
722
|
-
asymmetricMatch(other: unknown): boolean;
|
723
|
-
toString(): string;
|
724
|
-
getExpectedType(): string;
|
725
|
-
toAsymmetricMatcher(): string;
|
726
|
-
}
|
727
|
-
declare class StringMatching extends AsymmetricMatcher<RegExp> {
|
728
|
-
constructor(sample: string | RegExp, inverse?: boolean);
|
729
|
-
asymmetricMatch(other: string): boolean;
|
730
|
-
toString(): string;
|
731
|
-
getExpectedType(): string;
|
732
|
-
}
|
733
|
-
declare const JestAsymmetricMatchers: ChaiPlugin;
|
734
|
-
|
735
736
|
declare const JestChaiExpect: ChaiPlugin;
|
736
737
|
|
737
738
|
declare const JestExtend: ChaiPlugin;
|
@@ -761,4 +762,4 @@ declare function getState<State extends MatcherState = MatcherState>(expect: Exp
|
|
761
762
|
declare function setState<State extends MatcherState = MatcherState>(state: Partial<State>, expect: ExpectStatic): void;
|
762
763
|
|
763
764
|
export { ASYMMETRIC_MATCHERS_OBJECT, Any, Anything, ArrayContaining, AsymmetricMatcher, GLOBAL_EXPECT, JEST_MATCHERS_OBJECT, JestAsymmetricMatchers, JestChaiExpect, JestExtend, MATCHERS_OBJECT, ObjectContaining, StringContaining, StringMatching, addCustomEqualityTesters, arrayBufferEquality, customMatchers, equals, fnNameFor, generateToBeMessage, getObjectKeys, getObjectSubset, getState, hasAsymmetric, hasProperty, isA, isAsymmetric, isImmutableUnorderedKeyed, isImmutableUnorderedSet, iterableEquality, pluralize, setState, sparseArrayEquality, subsetEquality, typeEquality };
|
764
|
-
export type { Assertion, AsymmetricMatcherInterface, AsymmetricMatchersContaining, AsyncExpectationResult, ChaiPlugin, ExpectStatic, ExpectationResult, JestAssertion, MatcherHintOptions, MatcherState, MatchersObject, PromisifyAssertion, RawMatcherFn, SyncExpectationResult, Tester, TesterContext };
|
765
|
+
export type { Assertion, AsymmetricMatcherInterface, AsymmetricMatchersContaining, AsyncExpectationResult, ChaiPlugin, DeeplyAllowMatchers, ExpectStatic, ExpectationResult, JestAssertion, MatcherHintOptions, MatcherState, MatchersObject, PromisifyAssertion, RawMatcherFn, SyncExpectationResult, Tester, TesterContext };
|
package/dist/index.js
CHANGED
@@ -446,7 +446,7 @@ function iterableEquality(a, b, customTesters = [], aStack = [], bStack = []) {
|
|
446
446
|
if (!isImmutableList(a) && !isImmutableOrderedKeyed(a) && !isImmutableOrderedSet(a) && !isImmutableRecord(a)) {
|
447
447
|
const aEntries = Object.entries(a);
|
448
448
|
const bEntries = Object.entries(b);
|
449
|
-
if (!equals(aEntries, bEntries)) {
|
449
|
+
if (!equals(aEntries, bEntries, filteredCustomTesters)) {
|
450
450
|
return false;
|
451
451
|
}
|
452
452
|
}
|
package/package.json
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
{
|
2
2
|
"name": "@vitest/expect",
|
3
3
|
"type": "module",
|
4
|
-
"version": "3.
|
4
|
+
"version": "3.2.0-beta.2",
|
5
5
|
"description": "Jest's expect matchers as a Chai plugin",
|
6
6
|
"license": "MIT",
|
7
7
|
"funding": "https://opencollective.com/vitest",
|
@@ -30,15 +30,15 @@
|
|
30
30
|
"dist"
|
31
31
|
],
|
32
32
|
"dependencies": {
|
33
|
+
"@types/chai": "^5.2.2",
|
33
34
|
"chai": "^5.2.0",
|
34
35
|
"tinyrainbow": "^2.0.0",
|
35
|
-
"@vitest/
|
36
|
-
"@vitest/
|
36
|
+
"@vitest/spy": "3.2.0-beta.2",
|
37
|
+
"@vitest/utils": "3.2.0-beta.2"
|
37
38
|
},
|
38
39
|
"devDependencies": {
|
39
|
-
"@types/chai": "5.0.1",
|
40
40
|
"rollup-plugin-copy": "^3.5.0",
|
41
|
-
"@vitest/runner": "3.
|
41
|
+
"@vitest/runner": "3.2.0-beta.2"
|
42
42
|
},
|
43
43
|
"scripts": {
|
44
44
|
"build": "rimraf dist && rollup -c",
|