@vitest/expect 4.0.8 → 4.0.10

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
@@ -189,14 +189,14 @@ interface CustomMatcher {
189
189
  */
190
190
  toSatisfy: (matcher: (value: any) => boolean, message?: string) => any;
191
191
  /**
192
- * Matches if the received value is one of the values in the expected array.
192
+ * Matches if the received value is one of the values in the expected array or set.
193
193
  *
194
194
  * @example
195
195
  * expect(1).toBeOneOf([1, 2, 3])
196
196
  * expect('foo').toBeOneOf([expect.any(String)])
197
197
  * expect({ a: 1 }).toEqual({ a: expect.toBeOneOf(['1', '2', '3']) })
198
198
  */
199
- toBeOneOf: <T>(sample: Array<T>) => any;
199
+ toBeOneOf: <T>(sample: Array<T> | Set<T>) => any;
200
200
  }
201
201
  interface AsymmetricMatchersContaining extends CustomMatcher {
202
202
  /**
package/dist/index.js CHANGED
@@ -39,10 +39,14 @@ ${printReceived(actual)}`
39
39
  toBeOneOf(actual, expected) {
40
40
  const { equals, customTesters } = this;
41
41
  const { printReceived, printExpected, matcherHint } = this.utils;
42
- if (!Array.isArray(expected)) {
43
- throw new TypeError(`You must provide an array to ${matcherHint(".toBeOneOf")}, not '${typeof expected}'.`);
42
+ let pass;
43
+ if (Array.isArray(expected)) {
44
+ pass = expected.length === 0 || expected.some((item) => equals(item, actual, customTesters));
45
+ } else if (expected instanceof Set) {
46
+ pass = expected.size === 0 || expected.has(actual) || [...expected].some((item) => equals(item, actual, customTesters));
47
+ } else {
48
+ throw new TypeError(`You must provide an array or set to ${matcherHint(".toBeOneOf")}, not '${typeof expected}'.`);
44
49
  }
45
- const pass = expected.length === 0 || expected.some((item) => equals(item, actual, customTesters));
46
50
  return {
47
51
  pass,
48
52
  message: () => pass ? `\
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@vitest/expect",
3
3
  "type": "module",
4
- "version": "4.0.8",
4
+ "version": "4.0.10",
5
5
  "description": "Jest's expect matchers as a Chai plugin",
6
6
  "license": "MIT",
7
7
  "funding": "https://opencollective.com/vitest",
@@ -31,13 +31,13 @@
31
31
  "dependencies": {
32
32
  "@standard-schema/spec": "^1.0.0",
33
33
  "@types/chai": "^5.2.2",
34
- "chai": "^6.2.0",
34
+ "chai": "^6.2.1",
35
35
  "tinyrainbow": "^3.0.3",
36
- "@vitest/spy": "4.0.8",
37
- "@vitest/utils": "4.0.8"
36
+ "@vitest/spy": "4.0.10",
37
+ "@vitest/utils": "4.0.10"
38
38
  },
39
39
  "devDependencies": {
40
- "@vitest/runner": "4.0.8"
40
+ "@vitest/runner": "4.0.10"
41
41
  },
42
42
  "scripts": {
43
43
  "build": "premove dist && rollup -c",