jestjs/jest · error · Error

Property `${String(propertyKey)}` is not declared configurab

Error message

Property `${String(propertyKey)}` is not declared configurable

What it means

Thrown by _spyOnProperty when the located descriptor has configurable:false. Redefining a non-configurable accessor is forbidden by the JS engine, so Jest cannot install the spy.

Source

Thrown at packages/jest-mock/src/index.ts:1394

    let descriptor = Object.getOwnPropertyDescriptor(object, propertyKey);
    let proto = Object.getPrototypeOf(object);

    while (!descriptor && proto !== null) {
      descriptor = Object.getOwnPropertyDescriptor(proto, propertyKey);
      proto = Object.getPrototypeOf(proto);
    }

    if (!descriptor) {
      throw new Error(
        `Property \`${String(
          propertyKey,
        )}\` does not exist in the provided object`,
      );
    }

    if (!descriptor.configurable) {
      throw new Error(
        `Property \`${String(propertyKey)}\` is not declared configurable`,
      );
    }

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

    const original = descriptor[accessType];

    if (!this.isMockFunction(original)) {
      if (typeof original !== 'function') {
        throw new TypeError(
          `Cannot spy on the ${String(

View on GitHub (pinned to 8e6d128e4a)

Solutions

  1. Spy on a wrapper/proxy you control instead of the frozen object.
  2. Redefine the property as configurable before spying (only possible if it was configurable originally).
  3. Mock at the module level (jest.mock) rather than the property level.

Example fix

// before
jest.spyOn(frozenObj, 'x', 'get'); // configurable:false
// after
jest.mock('./config', () => ({...})); // mock the module instead
Defensive patterns

Strategy: validation

Validate before calling

const d = Object.getOwnPropertyDescriptor(obj, propertyKey);
if (d && !d.configurable) {
  // mock at module level instead
  jest.mock(modulePath, factory);
} else {
  jest.spyOn(obj, propertyKey, accessType);
}

Type guard

const isConfigurable = (o: object, k: PropertyKey): boolean =>
  Object.getOwnPropertyDescriptor(o, k)?.configurable === true;

Prevention

When it happens

Trigger: jest.spyOn(obj,'x','get') on a frozen object or a property declared non-configurable (some native/DOM/class fields, Object.freeze'd targets).

Common situations: Spying on built-in or host object accessors; objects sealed/frozen by a library; class fields emitted with configurable:false; React/internal framework objects.

Related errors


AI-assisted analysis of jestjs/jest@8e6d128e4a (2026-08-10). Data as JSON: /api/errors/ec5235e2215c8cf8. Report an issue: GitHub.