{"record":{"id":"c8a44997a738e58f","repo":"jestjs/jest","slug":"property-string-methodkey-does-not-exist-in","errorCode":null,"errorMessage":"Property `${String(methodKey)}` does not exist in the provided object","messagePattern":"Property `(.+?)` does not exist in the provided object","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/jest-mock/src/index.ts","lineNumber":1296,"sourceCode":"      (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') {\n        throw new TypeError(\n          `Cannot spy on the \\`${String(\n            methodKey,\n          )}\\` property because it is not a function; ${this._typeOf(\n            original,\n          )} given instead.${\n            typeof original === 'object'\n              ? ''\n              : ` If you are trying to mock a property, use \\`jest.replaceProperty(object, '${String(\n                  methodKey,","sourceCodeStart":1278,"sourceCodeEnd":1314,"githubUrl":"https://github.com/jestjs/jest/blob/8e6d128e4a278059ecddecaa97400b04c8ae5fd9/packages/jest-mock/src/index.ts#L1278-L1314","documentation":"Thrown by jest.spyOn when object[methodKey] is falsy. The spy reads the existing value to wrap it, so a missing/undefined property cannot be spied on. Note this is a truthiness check, so a property explicitly set to 0/''/false also triggers it.","triggerScenarios":"jest.spyOn(obj,'nonExistent'); jest.spyOn(obj,'count') when obj.count === 0; spying on a method only present on a sibling object.","commonSituations":"Misspelled method name; the method lives on the prototype/parent and the wrong reference was used; tree-shaking stripped the method; the property is set to a falsy non-function value.","solutions":["Verify the property exists and is truthy on the exact object reference (console.log(obj[methodKey])).","Spy on the prototype or the object that actually owns the method.","If the value is legitimately falsy, reconsider whether spyOn is the right tool (it only wraps functions)."],"exampleFix":"// before\njest.spyOn(repo, 'find'); // find is defined on Repo.prototype, repo.find is inherited\n// after\njest.spyOn(Repo.prototype, 'find');","handlingStrategy":"validation","validationCode":"if (!obj[methodKey]) {\n  throw new Error(`Cannot spyOn missing/falsy property ${String(methodKey)}`);\n}\njest.spyOn(obj, methodKey);","typeGuard":"const hasTruthyProp = <T extends object>(o: T, k: keyof T): boolean =>\n  Boolean(o[k]);","tryCatchPattern":null,"preventionTips":["console.log(obj[methodKey]) before spying during test setup.","Spy on the prototype when the method is inherited.","Confirm the method survives tree-shaking/bundling in your test transform."],"tags":["spy","mock","missing-property"],"backgroundTag":null,"analyzedSha":"8e6d128e4a278059ecddecaa97400b04c8ae5fd9","analyzedAt":"2026-08-10T18:11:27.960Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}