{"id":"da3fa524a506af87","repo":"vitest-dev/vitest","slug":"you-must-provide-an-array-to-this-tostring-n","errorCode":null,"errorMessage":"You must provide an array to ${this.toString()}, not '${typeof this.sample}'.","messagePattern":"You must provide an array to (.+?), not '(.+?)'\\.","errorType":"validation","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"packages/expect/src/jest-asymmetric-matchers.ts","lineNumber":201,"sourceCode":"  }\n\n  toString() {\n    return `Object${this.inverse ? 'Not' : ''}Containing`\n  }\n\n  getExpectedType() {\n    return 'object'\n  }\n}\n\nexport class ArrayContaining<T = unknown> extends AsymmetricMatcher<Array<T>> {\n  constructor(sample: Array<T>, inverse = false) {\n    super(sample, inverse)\n  }\n\n  asymmetricMatch(other: Array<T>, customTesters?: Array<Tester>): boolean {\n    if (!Array.isArray(this.sample)) {\n      throw new TypeError(\n        `You must provide an array to ${this.toString()}, not '${typeof this\n          .sample}'.`,\n      )\n    }\n\n    const result\n      = this.sample.length === 0\n        || (Array.isArray(other)\n          && this.sample.every(item =>\n            other.some(another =>\n              equals(item, another, customTesters),\n            ),\n          ))\n\n    return this.inverse ? !result : result\n  }\n\n  toString() {","sourceCodeStart":183,"sourceCodeEnd":219,"githubUrl":"https://github.com/vitest-dev/vitest/blob/d568f8ce3739b532d5bf2c1ee1e45e8a8a473d09/packages/expect/src/jest-asymmetric-matchers.ts#L183-L219","documentation":"Thrown as a TypeError inside ArrayContaining.asymmetricMatch when this.sample is not an array. ArrayContaining asserts the received value contains all expected elements, so the expected sample must be an array.","triggerScenarios":"Constructing expect.arrayContaining(value) where value is not an array (a single item, a Set, a plain object). The constructor stores it but matching throws on Array.isArray(this.sample) === false.","commonSituations":"Passing a single element instead of an array; passing a Set/Map where an array was expected; refactor changing the shape of the expected value.","solutions":["Wrap the elements in an array: expect.arrayContaining([1, 2]).","Spread an iterable into an array: expect.arrayContaining([...set]).","Use objectContaining or stringContaining for non-array semantics."],"exampleFix":"// before\nexpect(items).toEqual(expect.arrayContaining('alpha'))\n// after\nexpect(items).toEqual(expect.arrayContaining(['alpha']))","handlingStrategy":"type-guard","validationCode":"function asArray<T>(v: unknown): T[] {\n  if (!Array.isArray(v)) throw new TypeError(`arrayContaining needs an array, got ${typeof v}`)\n  return v as T[]\n}\nexpect(items).toEqual(expect.arrayContaining(asArray(expected)))","typeGuard":"function isArrayOf<T>(v: unknown): v is T[] {\n  return Array.isArray(v)\n}","tryCatchPattern":null,"preventionTips":["Always wrap elements in [] for arrayContaining.","Spread non-array iterables ([...set]) before passing.","Type expected values as unknown[] in shared helpers."],"tags":["expect","asymmetric-matcher","assertion","typescript"],"analyzedSha":"d568f8ce3739b532d5bf2c1ee1e45e8a8a473d09","analyzedAt":"2026-08-03T20:23:56.861Z","schemaVersion":2}