{"record":{"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/1fa9837ec26533512fdcad8baebf249771bd340a/packages/expect/src/custom-matchers.ts#L28-L64","documentation":"The toBeOneOf matcher requires its expected argument to be an Array or a Set; any other type raises a TypeError before equality is evaluated. An empty Array/Set passes by default (matches anything), but a primitive or plain object is rejected.","triggerScenarios":"expect(actual).toBeOneOf(expected) where expected is a string, number, object literal, Map, or any non-Array/non-Set value.","commonSituations":"Passing a single allowed value unwrapped (toBeOneOf('active') instead of toBeOneOf(['active'])); confusing toBeOneOf with toBe; passing a Map where a Set was intended.","solutions":["Wrap the candidate value(s) in an array: toBeOneOf(['active']).","Use a Set when testing membership against a large or deduplicated collection.","If you meant a single value, use toBe(value) instead."],"exampleFix":"// before\nexpect(status).toBeOneOf('active')\n// after\nexpect(status).toBeOneOf(['active', 'idle', 'blocked'])","handlingStrategy":"type-guard","validationCode":"function assertCandidates(v) {\n  if (!Array.isArray(v) && !(v instanceof Set)) {\n    throw new TypeError('toBeOneOf expects an Array or Set')\n  }\n}","typeGuard":"function isArrayOrSet(v): v is Array<unknown> | Set<unknown> {\n  return Array.isArray(v) || v instanceof Set\n}","tryCatchPattern":null,"preventionTips":["Always pass an array literal to toBeOneOf, even for a single value.","Use toBe(value) when only one value is acceptable.","Lint for toBeOneOf called with string/number literals."],"tags":["expect","matcher","type-error"],"backgroundTag":null,"analyzedSha":"1fa9837ec26533512fdcad8baebf249771bd340a","analyzedAt":"2026-08-11T16:11:39.638Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}