{"record":{"id":"5a142810594a690a","repo":"jestjs/jest","slug":"no-property-name-supplied","errorCode":null,"errorMessage":"No property name supplied","messagePattern":"No property name supplied","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/jest-mock/src/index.ts","lineNumber":1286,"sourceCode":"    methodKey: K,\n  ): V extends ClassLike | FunctionLike ? Spied<V> : never;\n\n  spyOn<T extends object>(\n    object: T,\n    methodKey: keyof T,\n    accessType?: 'get' | 'set',\n  ): MockInstance {\n    if (\n      object == null ||\n      (typeof object !== 'object' && typeof object !== 'function')\n    ) {\n      throw new Error(\n        `Cannot use spyOn on a primitive value; ${this._typeOf(object)} given`,\n      );\n    }\n\n    if (methodKey == null) {\n      throw new Error('No property name supplied');\n    }\n\n    if (accessType) {\n      return this._spyOnProperty(object, methodKey, accessType);\n    }\n\n    const original = object[methodKey];\n\n    if (!original) {\n      throw new Error(\n        `Property \\`${String(\n          methodKey,\n        )}\\` does not exist in the provided object`,\n      );\n    }\n\n    if (!this.isMockFunction(original)) {\n      if (typeof original !== 'function') {","sourceCodeStart":1268,"sourceCodeEnd":1304,"githubUrl":"https://github.com/jestjs/jest/blob/8e6d128e4a278059ecddecaa97400b04c8ae5fd9/packages/jest-mock/src/index.ts#L1268-L1304","documentation":"Thrown by jest.spyOn when the second argument (methodKey) is null or undefined. The spy needs the name of the property to intercept, so the guard rejects a missing name immediately.","triggerScenarios":"jest.spyOn(obj); jest.spyOn(obj, undefined); jest.spyOn(obj, methodName) where methodName is an undefined variable.","commonSituations":"Refactor removed the method but left the spyOn call; a typo in the variable name; a computed key built from an undefined value; forgetting the second argument entirely.","solutions":["Pass the property name as a string literal or a defined variable.","Check that any variable used as the key is defined before the spyOn call.","Search the codebase for usages of that key to confirm the intended name."],"exampleFix":"// before\njest.spyOn(obj, mathodName); // typo -> undefined\n// after\njest.spyOn(obj, 'methodName');","handlingStrategy":"validation","validationCode":"if (methodKey == null) {\n  throw new TypeError('spyOn requires a property name');\n}\njest.spyOn(obj, methodKey);","typeGuard":"const hasMethodName = (k: unknown): k is string | number | symbol =>\n  k != null;","tryCatchPattern":null,"preventionTips":["Pass property names as string literals where possible.","Run TypeScript so an undefined key variable is flagged.","Add a lint rule banning spyOn with fewer than 2 arguments."],"tags":["spy","mock","argument"],"backgroundTag":null,"analyzedSha":"8e6d128e4a278059ecddecaa97400b04c8ae5fd9","analyzedAt":"2026-08-10T18:11:27.960Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}