{"record":{"id":"f2b9875c01c696b6","repo":"awslabs/llrt","slug":"any-expects-to-be-passed-a-constructor-function-please-pass","errorCode":null,"errorMessage":"any() expects to be passed a constructor function. Please pass one or use anything() to match any object.","messagePattern":"any\\(\\) expects to be passed a constructor function\\. Please pass one or use anything\\(\\) to match any object\\.","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"llrt_core/src/modules/js/@llrt/expect/jest-asymmetric-matchers.ts","lineNumber":208,"sourceCode":"          other.some((another) => equals(item, another, []))\n        ));\n\n    return this.inverse ? !result : result;\n  }\n\n  toString() {\n    return `Array${this.inverse ? \"Not\" : \"\"}Containing`;\n  }\n\n  getExpectedType() {\n    return \"array\";\n  }\n}\n\nexport class Any extends AsymmetricMatcher<any> {\n  constructor(sample: unknown) {\n    if (typeof sample === \"undefined\") {\n      throw new TypeError(\n        \"any() expects to be passed a constructor function. \" +\n          \"Please pass one or use anything() to match any object.\"\n      );\n    }\n    super(sample);\n  }\n\n  fnNameFor(func: Function) {\n    if (func.name) return func.name;\n\n    const functionToString = Function.prototype.toString;\n\n    const matches = functionToString\n      .call(func)\n      .match(/^(?:async)?\\s*function\\s*\\*?\\s*([\\w$]+)\\s*\\(/);\n    return matches ? matches[1] : \"<anonymous>\";\n  }\n","sourceCodeStart":190,"sourceCodeEnd":226,"githubUrl":"https://github.com/awslabs/llrt/blob/742fc00b82cbeaab1c1b76f0d706c302a5cbc306/llrt_core/src/modules/js/@llrt/expect/jest-asymmetric-matchers.ts#L190-L226","documentation":"Any matches values by constructor function, so its constructor requires a defined sample. If expect.any() is called with undefined (typically by calling it with no arguments), it throws this TypeError and suggests using expect.anything() when any object/value should match.","triggerScenarios":"expect.any() with no argument, or a variable that evaluates to undefined at call time, e.g. expect.any(SomeType) where SomeType failed to import.","commonSituations":"Translating from expect.anything() and dropping the constructor argument, a broken import leaving the class undefined, or dynamically-selected constructors that end up undefined.","solutions":["Pass a constructor: expect.any(String), expect.any(Number), expect.any(MyClass).","Use expect.anything() if you want to match any non-null value.","Verify the constructor import/variable is defined (console.log or a module import fix).","Use expect.any(Array) via Array or expect.arrayContaining for arrays as appropriate."],"exampleFix":"// before\nexpect(payload).toEqual({ id: expect.any() });\n// after\nexpect(payload).toEqual({ id: expect.any(Number) });","handlingStrategy":"validation","validationCode":"if (ctor === undefined) throw new TypeError('expect.any requires a constructor; use expect.anything() to match any value');","typeGuard":"const isCtor = (v: unknown): v is Function => typeof v === 'function';","tryCatchPattern":"try { expect(v).toEqual(expect.any(ctor)); } catch (e) { /* ctor was undefined — check imports */ }","preventionTips":["Never call expect.any() without arguments","Use expect.anything() for any non-null value","Verify constructor imports resolve at runtime","List required constructors near test setup to catch undefined early"],"tags":["testing","missing-argument","asymmetric-matcher"],"backgroundTag":"missing-required-argument","analyzedSha":"742fc00b82cbeaab1c1b76f0d706c302a5cbc306","analyzedAt":"2026-09-12T11:14:07.838Z","contentChangedAt":"2026-09-12T11:14:07.838Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}