{"id":"2c275c724bab6fb5","repo":"jestjs/jest","slug":"property-propertykey-does-not-exist-in-the-pr","errorCode":null,"errorMessage":"Property `${propertyKey}` does not exist in the provided object","messagePattern":"Property `(.+?)` does not exist in the provided object","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/jest-mock/src/index.ts","lineNumber":1386,"sourceCode":"    object: T,\n    propertyKey: keyof T,\n    accessType: 'get' | 'set',\n  ): MockInstance {\n    const isPropertyOwner = Object.prototype.hasOwnProperty.call(\n      object,\n      propertyKey,\n    );\n\n    let descriptor = Object.getOwnPropertyDescriptor(object, propertyKey);\n    let proto = Object.getPrototypeOf(object);\n\n    while (!descriptor && proto !== null) {\n      descriptor = Object.getOwnPropertyDescriptor(proto, propertyKey);\n      proto = Object.getPrototypeOf(proto);\n    }\n\n    if (!descriptor) {\n      throw new Error(\n        `Property \\`${String(\n          propertyKey,\n        )}\\` does not exist in the provided object`,\n      );\n    }\n\n    if (!descriptor.configurable) {\n      throw new Error(\n        `Property \\`${String(propertyKey)}\\` is not declared configurable`,\n      );\n    }\n\n    if (!descriptor[accessType]) {\n      throw new Error(\n        `Property \\`${String(\n          propertyKey,\n        )}\\` does not have access type ${accessType}`,\n      );","sourceCodeStart":1368,"sourceCodeEnd":1404,"githubUrl":"https://github.com/jestjs/jest/blob/f49721c78e195558b40913977c9230f5b7f559d8/packages/jest-mock/src/index.ts#L1368-L1404","documentation":"Thrown by the internal _spyOnProperty (the path taken when spyOn is called with a third 'get'/'set' argument) when no property descriptor for propertyKey is found on the object or anywhere up its prototype chain. This is the accessor equivalent of error 145: the named property simply does not exist as a defined accessor.","triggerScenarios":"jest.spyOn(obj, 'missing', 'get'); jest.spyOn(obj, 'missing', 'set'); spying on an accessor before the class that defines it has been loaded; misspelled accessor name; the accessor was renamed in a library upgrade.","commonSituations":"Library version bump renamed/removed a getter; the accessor is defined via a mixin that hasn't been applied yet; typo in the property name.","solutions":["Verify the accessor exists at runtime: const d = Object.getOwnPropertyDescriptor(obj, 'key') || Object.getOwnPropertyDescriptor(Object.getPrototypeOf(obj), 'key'); console.log(d).","Fix the property name (case, spelling) against the current version of the library.","If you only need to replace a plain value (not an accessor), drop the third arg and use spyOn without 'get'/'set', or use replaceProperty."],"exampleFix":"// before\njest.spyOn(store, 'state', 'get'); // 'state' is not defined as a getter\n// after\njest.spyOn(store, 'getState'); // it's a method, not an accessor","handlingStrategy":"validation","validationCode":"function findDescriptor(o: object, k: PropertyKey) {\n  let d = Object.getOwnPropertyDescriptor(o, k);\n  let p = Object.getPrototypeOf(o);\n  while (!d && p) { d = Object.getOwnPropertyDescriptor(p, k); p = Object.getPrototypeOf(p); }\n  return d;\n}\nif (!findDescriptor(obj, key)) {\n  throw new Error(`accessor '${String(key)}' does not exist`);\n}\njest.spyOn(obj, key, 'get');","typeGuard":"const hasAccessor = (o: object, k: PropertyKey, t: 'get' | 'set') => {\n  let d = Object.getOwnPropertyDescriptor(o, k);\n  let p = Object.getPrototypeOf(o);\n  while (!d && p) { d = Object.getOwnPropertyDescriptor(p, k); p = Object.getPrototypeOf(p); }\n  return !!(d && d[t]);\n};\n\nif (hasAccessor(obj, key, 'get')) {\n  jest.spyOn(obj, key, 'get');\n}","tryCatchPattern":null,"preventionTips":["Verify the accessor exists with getOwnPropertyDescriptor before spying.","Check the property name against the current library version after upgrades.","Drop the third arg if the target is actually a method, not an accessor."],"tags":["jest-mock","spyon","accessor","missing-property"],"analyzedSha":"f49721c78e195558b40913977c9230f5b7f559d8","analyzedAt":"2026-08-03T20:16:28.571Z","schemaVersion":2}