{"id":"3a01f052e9874f33","repo":"vitest-dev/vitest","slug":"you-must-provide-an-array-or-set-to-matcherhint","errorCode":null,"errorMessage":"You must provide an array or set to ${matcherHint('.toBeOneOf')}, not '${typeof expected}'.","messagePattern":"You must provide an array or set to (.+?), not '(.+?)'\\.","errorType":"validation","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"packages/expect/src/custom-matchers.ts","lineNumber":46,"sourceCode":"  },\n\n  toBeOneOf(actual: unknown, expected: Array<unknown> | Set<unknown>) {\n    const { equals, customTesters } = this\n    const { printReceived, printExpected, matcherHint } = this.utils\n\n    let pass: boolean\n\n    if (Array.isArray(expected)) {\n      pass = expected.length === 0\n        || expected.some(item =>\n          equals(item, actual, customTesters),\n        )\n    }\n    else if (expected instanceof Set) {\n      pass = expected.size === 0 || expected.has(actual) || [...expected].some(item => equals(item, actual, customTesters))\n    }\n    else {\n      throw new TypeError(\n        `You must provide an array or set to ${matcherHint('.toBeOneOf')}, not '${typeof expected}'.`,\n      )\n    }\n\n    return {\n      pass,\n      message: () =>\n        pass\n          ? `\\\n${matcherHint('.not.toBeOneOf', 'received', '')}\n\nExpected value to not be one of:\n${printExpected(expected)}\nReceived:\n${printReceived(actual)}`\n          : `\\\n${matcherHint('.toBeOneOf', 'received', '')}\n","sourceCodeStart":28,"sourceCodeEnd":64,"githubUrl":"https://github.com/vitest-dev/vitest/blob/d568f8ce3739b532d5bf2c1ee1e45e8a8a473d09/packages/expect/src/custom-matchers.ts#L28-L64","documentation":"Thrown as a TypeError by the toBeOneOf matcher (ported from jest-extended) when the 'expected' argument is neither an Array nor a Set. toBeOneOf asserts the received value equals one of the provided candidates, so it needs an iterable collection to search.","triggerScenarios":"Calling expect(x).toBeOneOf(value) where value is a primitive, plain object, map, or any non-array/non-set. The matcher branches on Array.isArray then instanceof Set and throws in the else.","commonSituations":"Passing a comma-separated list as a single value, an object literal instead of an array, or a Map/Iterable that isn't a Set; refactoring a value from an array to something else and forgetting to update the assertion.","solutions":["Wrap candidates in an array: expect(x).toBeOneOf(['a', 'b']).","Or use a Set: expect(x).toBeOneOf(new Set(['a', 'b'])).","If you have another iterable, spread it into an array first."],"exampleFix":"// before\nexpect(status).toBeOneOf('active', 'idle') // not an array\n// after\nexpect(status).toBeOneOf(['active', 'idle'])","handlingStrategy":"type-guard","validationCode":"function asCollection<T>(v: T[] | Set<T> | unknown): T[] | Set<T> {\n  if (Array.isArray(v) || v instanceof Set) return v as T[] | Set<T>\n  throw new TypeError(`toBeOneOf needs an array or Set, got ${typeof v}`)\n}\nexpect(x).toBeOneOf(asCollection(candidates))","typeGuard":"function isArrayOfOrSet<T>(v: unknown): v is T[] | Set<T> {\n  return Array.isArray(v) || v instanceof Set\n}","tryCatchPattern":null,"preventionTips":["Always pass an array literal to toBeOneOf.","Type the expected argument as Array<unknown> | Set<unknown> in your helpers.","Lint against calling toBeOneOf with variadic args."],"tags":["expect","matcher","assertion","typescript"],"analyzedSha":"d568f8ce3739b532d5bf2c1ee1e45e8a8a473d09","analyzedAt":"2026-08-03T20:23:56.861Z","schemaVersion":2}