@vitest/expect 3.0.0-beta.2 → 3.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 +9 -0
- package/dist/index.js +28 -1
- package/package.json +4 -4
package/dist/index.d.ts
CHANGED
@@ -109,6 +109,15 @@ interface CustomMatcher {
|
|
109
109
|
* expect(age).toEqual(expect.toSatisfy(val => val >= 18, 'Age must be at least 18'));
|
110
110
|
*/
|
111
111
|
toSatisfy: (matcher: (value: any) => boolean, message?: string) => any;
|
112
|
+
/**
|
113
|
+
* Matches if the received value is one of the values in the expected array.
|
114
|
+
*
|
115
|
+
* @example
|
116
|
+
* expect(1).toBeOneOf([1, 2, 3])
|
117
|
+
* expect('foo').toBeOneOf([expect.any(String)])
|
118
|
+
* expect({ a: 1 }).toEqual({ a: expect.toBeOneOf(['1', '2', '3']) })
|
119
|
+
*/
|
120
|
+
toBeOneOf: <T>(sample: Array<T>) => any;
|
112
121
|
}
|
113
122
|
interface AsymmetricMatchersContaining extends CustomMatcher {
|
114
123
|
/**
|
package/dist/index.js
CHANGED
@@ -28,6 +28,33 @@ ${printReceived(actual)}` : `${matcherHint(".toSatisfy", "received", "")}
|
|
28
28
|
Expected value to satisfy:
|
29
29
|
${message || printExpected(expected)}
|
30
30
|
|
31
|
+
Received:
|
32
|
+
${printReceived(actual)}`
|
33
|
+
};
|
34
|
+
},
|
35
|
+
toBeOneOf(actual, expected) {
|
36
|
+
const { equals, customTesters } = this;
|
37
|
+
const { printReceived, printExpected, matcherHint } = this.utils;
|
38
|
+
if (!Array.isArray(expected)) {
|
39
|
+
throw new TypeError(
|
40
|
+
`You must provide an array to ${matcherHint(".toBeOneOf")}, not '${typeof expected}'.`
|
41
|
+
);
|
42
|
+
}
|
43
|
+
const pass = expected.length === 0 || expected.some(
|
44
|
+
(item) => equals(item, actual, customTesters)
|
45
|
+
);
|
46
|
+
return {
|
47
|
+
pass,
|
48
|
+
message: () => pass ? `${matcherHint(".not.toBeOneOf", "received", "")}
|
49
|
+
|
50
|
+
Expected value to not be one of:
|
51
|
+
${printExpected(expected)}
|
52
|
+
Received:
|
53
|
+
${printReceived(actual)}` : `${matcherHint(".toBeOneOf", "received", "")}
|
54
|
+
|
55
|
+
Expected value to be one of:
|
56
|
+
${printExpected(expected)}
|
57
|
+
|
31
58
|
Received:
|
32
59
|
${printReceived(actual)}`
|
33
60
|
};
|
@@ -2139,7 +2166,7 @@ function JestExtendPlugin(c, expect, matchers) {
|
|
2139
2166
|
return "any";
|
2140
2167
|
}
|
2141
2168
|
toAsymmetricMatcher() {
|
2142
|
-
return `${this.toString()}<${this.sample.map(
|
2169
|
+
return `${this.toString()}<${this.sample.map((item) => stringify(item)).join(", ")}>`;
|
2143
2170
|
}
|
2144
2171
|
}
|
2145
2172
|
const customMatcher = (...sample) => new CustomMatcher(false, ...sample);
|
package/package.json
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
{
|
2
2
|
"name": "@vitest/expect",
|
3
3
|
"type": "module",
|
4
|
-
"version": "3.0.0-beta.
|
4
|
+
"version": "3.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",
|
@@ -32,13 +32,13 @@
|
|
32
32
|
"dependencies": {
|
33
33
|
"chai": "^5.1.2",
|
34
34
|
"tinyrainbow": "^1.2.0",
|
35
|
-
"@vitest/spy": "3.0.0-beta.
|
36
|
-
"@vitest/utils": "3.0.0-beta.
|
35
|
+
"@vitest/spy": "3.0.0-beta.3",
|
36
|
+
"@vitest/utils": "3.0.0-beta.3"
|
37
37
|
},
|
38
38
|
"devDependencies": {
|
39
39
|
"@types/chai": "4.3.6",
|
40
40
|
"rollup-plugin-copy": "^3.5.0",
|
41
|
-
"@vitest/runner": "3.0.0-beta.
|
41
|
+
"@vitest/runner": "3.0.0-beta.3"
|
42
42
|
},
|
43
43
|
"scripts": {
|
44
44
|
"build": "rimraf dist && rollup -c",
|