jestjs/jest · error · Error

Property ${propertyName} does not have access type ${accessT

Error message

Property ${propertyName} does not have access type ${accessType}

What it means

Thrown by `SpyRegistry._spyOnProperty` in spyRegistry.ts:184 when `descriptor[accessType]` is falsy — i.e. you asked to spy on the 'get' accessor but only a 'set' exists (or vice versa). `accessType` defaults to `'get'`.

Source

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

      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) {
          return obj[propertyName];
        } else {
          throw new Error(
            getErrorMsg(`${propertyName} has already been spied upon`),
          );
        }
      }

      const originalDescriptor = descriptor;
      const spiedProperty = createSpy(propertyName, descriptor[accessType]);

View on GitHub (pinned to f49721c78e)

Solutions

  1. Inspect the descriptor to see which accessor exists: `Object.getOwnPropertyDescriptor(obj, 'name')`.
  2. Pass the matching access type: `spyOnProperty(obj, 'prop', 'set')` for a setter.
  3. If the property is a plain data property (no accessors), use `spyOn` instead of `spyOnProperty`.

Example fix

// before
spyOnProperty(store, 'value', 'get') // only has setter
// after
spyOnProperty(store, 'value', 'set')
Defensive patterns

Strategy: validation

Validate before calling

const d = Object.getOwnPropertyDescriptor(obj, propertyName);
const accessType = d?.get ? 'get' : d?.set ? 'set' : null;
if (!accessType) { throw new Error('no accessor found'); }
spyOnProperty(obj, propertyName, accessType);

Type guard

const pickAccessType = (d?: PropertyDescriptor): 'get' | 'set' | null =>
  d?.get ? 'get' : d?.set ? 'set' : null;

Prevention

When it happens

Trigger: Calling `spyOnProperty(obj, 'writeOnly', 'get')` on a property that only has a setter; calling with the default 'get' on a write-only property; typo in the access type string.

Common situations: Write-only properties (rare); misunderstanding which accessor exists; defaulting to 'get' without checking the descriptor.

Related errors


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