jestjs/jest · error · Error

${propertyName} property does not exist

Error message

${propertyName} property does not exist

What it means

Thrown by `SpyRegistry._spyOnProperty` in spyRegistry.ts:174 when `Object.getOwnPropertyDescriptor(obj, propertyName)` returns undefined. The property must exist as an own descriptor (or be resolvable) for jasmine to redefine it.

Source

Thrown at packages/jest-jasmine2/src/jasmine/spyRegistry.ts:174

          getErrorMsg(
            `could not find an object to spy upon for ${propertyName}`,
          ),
        );
      }

      if (!propertyName) {
        throw new Error(getErrorMsg('No property name supplied'));
      }

      let descriptor: PropertyDescriptor | undefined;
      try {
        descriptor = Object.getOwnPropertyDescriptor(obj, propertyName);
      } catch {
        // IE 8 doesn't support `definePropery` on non-DOM nodes
      }

      if (!descriptor) {
        throw new Error(getErrorMsg(`${propertyName} property does not exist`));
      }

      if (!descriptor.configurable) {
        throw new Error(
          getErrorMsg(`${propertyName} is not declared configurable`),
        );
      }

      if (!descriptor[accessType]) {
        throw new Error(
          getErrorMsg(
            `Property ${propertyName} does not have access type ${accessType}`,
          ),
        );
      }

      if (obj[propertyName] && isSpy(obj[propertyName])) {
        if (this.respy) {

View on GitHub (pinned to f49721c78e)

Solutions

  1. Verify the property exists: `Object.getOwnPropertyDescriptor(obj, 'name')`.
  2. If inherited, spy on the prototype that defines it: `spyOnProperty(Proto.prototype, 'name', 'get')`.
  3. After an upgrade, confirm the property still exists in the new version.

Example fix

// before
spyOnProperty(instance, 'cachedValue', 'get') // lives on prototype
// after
spyOnProperty(Proto.prototype, 'cachedValue', 'get')
Defensive patterns

Strategy: validation

Validate before calling

if (!Object.getOwnPropertyDescriptor(obj, propertyName)) { throw new Error(`${propertyName} has no own descriptor`); }
spyOnProperty(obj, propertyName, 'get');

Type guard

const hasOwnDescriptor = (o: object, p: string): boolean =>
  Boolean(Object.getOwnPropertyDescriptor(o, p));

Prevention

When it happens

Trigger: Calling `spyOnProperty(obj, 'missing', 'get')` where the property does not exist on the object; spying on a symbol-keyed property with the wrong name; the property is inherited and has no own descriptor.

Common situations: Renaming a getter without updating tests; spying on an instance when the getter lives on the prototype (must spy on the prototype); library version that removed the property.

Related errors


AI-assisted analysis of jestjs/jest@f49721c78e (2026-08-03). Data as JSON: /data/errors/44a6e94e48a25893.json. Report an issue: GitHub.