@vitest/expect 4.0.0-beta.2 → 4.0.0-beta.3
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 +27 -19
- package/dist/index.js +21 -3
- package/package.json +5 -5
package/dist/index.d.ts
CHANGED
|
@@ -43,10 +43,11 @@ declare class Anything extends AsymmetricMatcher<void> {
|
|
|
43
43
|
toString(): string;
|
|
44
44
|
toAsymmetricMatcher(): string;
|
|
45
45
|
}
|
|
46
|
-
declare class ObjectContaining extends AsymmetricMatcher<Record<string, unknown>> {
|
|
46
|
+
declare class ObjectContaining extends AsymmetricMatcher<Record<string | symbol | number, unknown>> {
|
|
47
47
|
constructor(sample: Record<string, unknown>, inverse?: boolean);
|
|
48
48
|
getPrototype(obj: object): any;
|
|
49
|
-
hasProperty(obj: object | null, property: string): boolean;
|
|
49
|
+
hasProperty(obj: object | null, property: string | symbol): boolean;
|
|
50
|
+
getProperties(obj: object): (string | symbol)[];
|
|
50
51
|
asymmetricMatch(other: any): boolean;
|
|
51
52
|
toString(): string;
|
|
52
53
|
getExpectedType(): string;
|
|
@@ -77,17 +78,17 @@ declare function matcherHint(matcherName: string, received?: string, expected?:
|
|
|
77
78
|
declare function printReceived(object: unknown): string;
|
|
78
79
|
declare function printExpected(value: unknown): string;
|
|
79
80
|
declare function getMatcherUtils(): {
|
|
80
|
-
EXPECTED_COLOR: Formatter
|
|
81
|
-
RECEIVED_COLOR: Formatter
|
|
82
|
-
INVERTED_COLOR: Formatter
|
|
83
|
-
BOLD_WEIGHT: Formatter
|
|
84
|
-
DIM_COLOR: Formatter
|
|
85
|
-
diff: typeof diff
|
|
86
|
-
matcherHint: typeof matcherHint
|
|
87
|
-
printReceived: typeof printReceived
|
|
88
|
-
printExpected: typeof printExpected
|
|
89
|
-
printDiffOrStringify: typeof printDiffOrStringify
|
|
90
|
-
printWithType: typeof printWithType
|
|
81
|
+
EXPECTED_COLOR: Formatter;
|
|
82
|
+
RECEIVED_COLOR: Formatter;
|
|
83
|
+
INVERTED_COLOR: Formatter;
|
|
84
|
+
BOLD_WEIGHT: Formatter;
|
|
85
|
+
DIM_COLOR: Formatter;
|
|
86
|
+
diff: typeof diff;
|
|
87
|
+
matcherHint: typeof matcherHint;
|
|
88
|
+
printReceived: typeof printReceived;
|
|
89
|
+
printExpected: typeof printExpected;
|
|
90
|
+
printDiffOrStringify: typeof printDiffOrStringify;
|
|
91
|
+
printWithType: typeof printWithType;
|
|
91
92
|
};
|
|
92
93
|
declare function printWithType<T>(name: string, value: T, print: (value: T) => string): string;
|
|
93
94
|
declare function addCustomEqualityTesters(newTesters: Array<Tester>): void;
|
|
@@ -135,10 +136,10 @@ interface MatcherState {
|
|
|
135
136
|
suppressedErrors: Array<Error>;
|
|
136
137
|
testPath?: string;
|
|
137
138
|
utils: ReturnType<typeof getMatcherUtils> & {
|
|
138
|
-
diff: typeof diff
|
|
139
|
-
stringify: typeof stringify
|
|
140
|
-
iterableEquality: Tester
|
|
141
|
-
subsetEquality: Tester
|
|
139
|
+
diff: typeof diff;
|
|
140
|
+
stringify: typeof stringify;
|
|
141
|
+
iterableEquality: Tester;
|
|
142
|
+
subsetEquality: Tester;
|
|
142
143
|
};
|
|
143
144
|
soft?: boolean;
|
|
144
145
|
poll?: boolean;
|
|
@@ -366,6 +367,13 @@ interface JestAssertion<T = any> extends jest.Matchers<void, T>, CustomMatcher {
|
|
|
366
367
|
*/
|
|
367
368
|
toBeNull: () => void;
|
|
368
369
|
/**
|
|
370
|
+
* Used to check that a variable is nullable (null or undefined).
|
|
371
|
+
*
|
|
372
|
+
* @example
|
|
373
|
+
* expect(value).toBeNullable();
|
|
374
|
+
*/
|
|
375
|
+
toBeNullable: () => void;
|
|
376
|
+
/**
|
|
369
377
|
* Ensure that a variable is not undefined.
|
|
370
378
|
*
|
|
371
379
|
* @example
|
|
@@ -797,8 +805,8 @@ declare function generateToBeMessage(deepEqualityName: string, expected?: string
|
|
|
797
805
|
declare function pluralize(word: string, count: number): string;
|
|
798
806
|
declare function getObjectKeys(object: object): Array<string | symbol>;
|
|
799
807
|
declare function getObjectSubset(object: any, subset: any, customTesters: Array<Tester>): {
|
|
800
|
-
subset: any
|
|
801
|
-
stripped: number
|
|
808
|
+
subset: any;
|
|
809
|
+
stripped: number;
|
|
802
810
|
};
|
|
803
811
|
|
|
804
812
|
declare function getState<State extends MatcherState = MatcherState>(expect: ExpectStatic): State;
|
package/dist/index.js
CHANGED
|
@@ -769,19 +769,33 @@ class ObjectContaining extends AsymmetricMatcher {
|
|
|
769
769
|
if (!obj) {
|
|
770
770
|
return false;
|
|
771
771
|
}
|
|
772
|
-
if (Object.
|
|
772
|
+
if (Object.hasOwn(obj, property)) {
|
|
773
773
|
return true;
|
|
774
774
|
}
|
|
775
775
|
return this.hasProperty(this.getPrototype(obj), property);
|
|
776
776
|
}
|
|
777
|
+
getProperties(obj) {
|
|
778
|
+
return [...Object.keys(obj), ...Object.getOwnPropertySymbols(obj).filter((s) => {
|
|
779
|
+
var _Object$getOwnPropert;
|
|
780
|
+
return (_Object$getOwnPropert = Object.getOwnPropertyDescriptor(obj, s)) === null || _Object$getOwnPropert === void 0 ? void 0 : _Object$getOwnPropert.enumerable;
|
|
781
|
+
})];
|
|
782
|
+
}
|
|
777
783
|
asymmetricMatch(other) {
|
|
778
784
|
if (typeof this.sample !== "object") {
|
|
779
785
|
throw new TypeError(`You must provide an object to ${this.toString()}, not '${typeof this.sample}'.`);
|
|
780
786
|
}
|
|
781
787
|
let result = true;
|
|
782
788
|
const matcherContext = this.getMatcherContext();
|
|
783
|
-
|
|
784
|
-
|
|
789
|
+
const properties = this.getProperties(this.sample);
|
|
790
|
+
for (const property of properties) {
|
|
791
|
+
var _Object$getOwnPropert2, _Object$getOwnPropert3;
|
|
792
|
+
if (!this.hasProperty(other, property)) {
|
|
793
|
+
result = false;
|
|
794
|
+
break;
|
|
795
|
+
}
|
|
796
|
+
const value = ((_Object$getOwnPropert2 = Object.getOwnPropertyDescriptor(this.sample, property)) === null || _Object$getOwnPropert2 === void 0 ? void 0 : _Object$getOwnPropert2.value) ?? this.sample[property];
|
|
797
|
+
const otherValue = ((_Object$getOwnPropert3 = Object.getOwnPropertyDescriptor(other, property)) === null || _Object$getOwnPropert3 === void 0 ? void 0 : _Object$getOwnPropert3.value) ?? other[property];
|
|
798
|
+
if (!equals(value, otherValue, matcherContext.customTesters)) {
|
|
785
799
|
result = false;
|
|
786
800
|
break;
|
|
787
801
|
}
|
|
@@ -1241,6 +1255,10 @@ const JestChaiExpect = (chai, utils) => {
|
|
|
1241
1255
|
const obj = utils.flag(this, "object");
|
|
1242
1256
|
this.assert(obj === null, "expected #{this} to be null", "expected #{this} not to be null", null, obj);
|
|
1243
1257
|
});
|
|
1258
|
+
def("toBeNullable", function() {
|
|
1259
|
+
const obj = utils.flag(this, "object");
|
|
1260
|
+
this.assert(obj == null, "expected #{this} to be nullish", "expected #{this} not to be nullish", null, obj);
|
|
1261
|
+
});
|
|
1244
1262
|
def("toBeDefined", function() {
|
|
1245
1263
|
const obj = utils.flag(this, "object");
|
|
1246
1264
|
this.assert(typeof obj !== "undefined", "expected #{this} to be defined", "expected #{this} to be undefined", obj);
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vitest/expect",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "4.0.0-beta.
|
|
4
|
+
"version": "4.0.0-beta.3",
|
|
5
5
|
"description": "Jest's expect matchers as a Chai plugin",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"funding": "https://opencollective.com/vitest",
|
|
@@ -30,14 +30,14 @@
|
|
|
30
30
|
],
|
|
31
31
|
"dependencies": {
|
|
32
32
|
"@types/chai": "^5.2.2",
|
|
33
|
-
"chai": "^5.2.
|
|
33
|
+
"chai": "^5.2.1",
|
|
34
34
|
"tinyrainbow": "^2.0.0",
|
|
35
|
-
"@vitest/spy": "4.0.0-beta.
|
|
36
|
-
"@vitest/utils": "4.0.0-beta.
|
|
35
|
+
"@vitest/spy": "4.0.0-beta.3",
|
|
36
|
+
"@vitest/utils": "4.0.0-beta.3"
|
|
37
37
|
},
|
|
38
38
|
"devDependencies": {
|
|
39
39
|
"rollup-plugin-copy": "^3.5.0",
|
|
40
|
-
"@vitest/runner": "4.0.0-beta.
|
|
40
|
+
"@vitest/runner": "4.0.0-beta.3"
|
|
41
41
|
},
|
|
42
42
|
"scripts": {
|
|
43
43
|
"build": "rimraf dist && rollup -c",
|