jestjs/jest · error · Error
<spyOn> : No property name supplied Usage: spyOn(<object>, <
Error message
<spyOn> : No property name supplied Usage: spyOn(<object>, <methodName>)
What it means
Thrown by SpyRegistry._spyOnProperty when propertyName is falsy (spyRegistry.ts:162-164). The property name selects which accessor descriptor to replace; without it the registry cannot locate the getter/setter to spy on.
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 8e6d128e4a)
Solutions
- Pass the literal property name: spyOn(obj, 'value', 'get').
- If dynamic, validate first: if (!name) throw new Error('property name required'); spyOn(obj, name, 'get').
- Type propertyName as keyof typeof obj to catch undefined at compile time.
- Review auto-formatter output that may have dropped a line.
Example fix
// before spyOn(obj, undefined, 'get'); // after spyOn(obj, 'value', 'get');
Defensive patterns
Strategy: validation
Validate before calling
if (!propertyName) {
throw new Error('spyOn property: propertyName is required');
}
spyOn(obj, propertyName, 'get'); Type guard
const isPropertyName = (v: unknown): v is string => typeof v === 'string' && v.length > 0;
Prevention
- Pass a non-empty property name string.
- Type propertyName as keyof typeof obj.
- Review formatter output after refactors.
When it happens
Trigger: spyOn(obj, undefined, 'get'), spyOn(obj, '', 'get'), spyOn(obj) with the accessType arg pushed out, or a dynamically-computed name that resolved to an empty string.
Common situations: Refactor that renamed the property but left the spy on the old name variable computed elsewhere; destructuring that lost the name; copy-paste of a spy template that omitted the second arg.
Related errors
- <spyOn> : could not find an object to spy upon for ${propert
- <spyOn> : could not find an object to spy upon for ${methodN
- <spyOn> : No method name supplied Usage: spyOn(<object>, <me
- <spyOn> : ${propertyName} property does not exist Usage: spy
- Property ${propertyName} does not have access type ${accessT
AI-assisted analysis of jestjs/jest@8e6d128e4a (2026-08-10).
Data as JSON: /api/errors/6e12a6b48fe84d43.
Report an issue: GitHub.