{"record":{"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/1fa9837ec26533512fdcad8baebf249771bd340a/packages/expect/src/jest-asymmetric-matchers.ts#L183-L219","documentation":"ArrayContaining's asymmetricMatch throws a TypeError if this.sample is not an array. Like objectContaining, this fires at match time when the matcher is evaluated, not at construction. An empty array passes against any array (vacuous containment).","triggerScenarios":"expect.arrayContaining(sample) built with a non-array sample, then used in toEqual/toEqual-like assertions.","commonSituations":"Passing a single value instead of an array (arrayContaining(1) instead of arrayContaining([1])); passing a Set (use [...set]); passing an object where a list was intended.","solutions":["Wrap the expected items in an array: expect.arrayContaining([1, 2, 3]).","Spread iterable sources: expect.arrayContaining([...setOfIds]).","For a single item, still use an array literal of length 1."],"exampleFix":"// before\nexpect(ids).toEqual(expect.arrayContaining(42))\n// after\nexpect(ids).toEqual(expect.arrayContaining([42, 43]))","handlingStrategy":"type-guard","validationCode":"function asArrayContaining(sample) {\n  if (!Array.isArray(sample)) {\n    throw new TypeError('expect.arrayContaining needs an array')\n  }\n  return expect.arrayContaining(sample)\n}","typeGuard":"function isUnknownArray(v): v is unknown[] {\n  return Array.isArray(v)\n}","tryCatchPattern":null,"preventionTips":["Pass an array literal to expect.arrayContaining.","Spread sets/iterables into an array first.","Note this fires at match time, so unit-test the matcher in isolation."],"tags":["expect","asymmetric-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"}