···379379380380## toBeOneOf
381381382382-- **Type:** `(sample: Array<any>) => any`
382382+- **Type:** `(sample: Array<any> | Set<any>) => any`
383383384384-`toBeOneOf` asserts if a value matches any of the values in the provided array.
384384+`toBeOneOf` asserts if a value matches any of the values in the provided array or set.
385385+386386+::: warning EXPERIMENTAL
387387+Providing a `Set` is an experimental feature and may change in a future release.
388388+:::
385389386390```ts
387391import { expect, test } from 'vitest'
+14-8
packages/expect/src/custom-matchers.ts
···2727 }
2828 },
29293030- toBeOneOf(actual: unknown, expected: Array<unknown>) {
3030+ toBeOneOf(actual: unknown, expected: Array<unknown> | Set<unknown>) {
3131 const { equals, customTesters } = this
3232 const { printReceived, printExpected, matcherHint } = this.utils
33333434- if (!Array.isArray(expected)) {
3434+ let pass: boolean
3535+3636+ if (Array.isArray(expected)) {
3737+ pass = expected.length === 0
3838+ || expected.some(item =>
3939+ equals(item, actual, customTesters),
4040+ )
4141+ }
4242+ else if (expected instanceof Set) {
4343+ pass = expected.size === 0 || expected.has(actual) || [...expected].some(item => equals(item, actual, customTesters))
4444+ }
4545+ else {
3546 throw new TypeError(
3636- `You must provide an array to ${matcherHint('.toBeOneOf')}, not '${typeof expected}'.`,
4747+ `You must provide an array or set to ${matcherHint('.toBeOneOf')}, not '${typeof expected}'.`,
3748 )
3849 }
3939-4040- const pass = expected.length === 0
4141- || expected.some(item =>
4242- equals(item, actual, customTesters),
4343- )
44504551 return {
4652 pass,
+2-2
packages/expect/src/types.ts
···129129 toSatisfy: (matcher: (value: any) => boolean, message?: string) => any
130130131131 /**
132132- * Matches if the received value is one of the values in the expected array.
132132+ * Matches if the received value is one of the values in the expected array or set.
133133 *
134134 * @example
135135 * expect(1).toBeOneOf([1, 2, 3])
136136 * expect('foo').toBeOneOf([expect.any(String)])
137137 * expect({ a: 1 }).toEqual({ a: expect.toBeOneOf(['1', '2', '3']) })
138138 */
139139- toBeOneOf: <T>(sample: Array<T>) => any
139139+ toBeOneOf: <T>(sample: Array<T> | Set<T>) => any
140140}
141141142142export interface AsymmetricMatchersContaining extends CustomMatcher {