jestjs/jest · error · Error

No property name supplied

Error message

No property name supplied

What it means

Thrown by `SpyRegistry._spyOnProperty` in spyRegistry.ts:163 when `propertyName` is falsy. The registry needs an explicit property name string to look up the descriptor via `Object.getOwnPropertyDescriptor`.

Source

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

        restoreObjectToOriginalState: restoreStrategy,
      } as Spy);

      obj[methodName] = spiedMethod;

      return spiedMethod;
    };

    this._spyOnProperty = function (obj, propertyName, accessType = 'get') {
      if (!obj) {
        throw new Error(
          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`),
        );
      }

View on GitHub (pinned to f49721c78e)

Solutions

  1. Supply the property name as a string literal: `spyOnProperty(obj, 'prop', 'get')`.
  2. If dynamic, assert the variable is a non-empty string before spying.
  3. Remember the arity: object, name, and access type ('get'|'set').

Example fix

// before
spyOnProperty(config, undefined, 'get')
// after
spyOnProperty(config, 'baseUrl', 'get')
Defensive patterns

Strategy: validation

Validate before calling

if (typeof propertyName !== 'string' || !propertyName) { throw new TypeError('spyOnProperty needs a property name'); }
spyOnProperty(obj, propertyName, 'get');

Type guard

const isPropName = (s: unknown): s is string => typeof s === 'string' && s.length > 0;

Prevention

When it happens

Trigger: Calling `spyOnProperty(obj)` with one arg, `spyOnProperty(obj, undefined, 'get')`, or `spyOnProperty(obj, missingVar, 'get')`.

Common situations: Typo in a dynamic property name variable; refactor dropping the second arg; misremembering the `spyOnProperty(obj, name, accessType)` arity.

Related errors


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