jestjs/jest · error · Error
No property name supplied
Error message
No property name supplied
What it means
Thrown by jest.spyOn when the second argument (methodKey) is null or undefined. The spy needs the name of the property to intercept, so the guard rejects a missing name immediately.
Solutions
- Pass the property name as a string literal or a defined variable.
- Check that any variable used as the key is defined before the spyOn call.
- Search the codebase for usages of that key to confirm the intended name.
Example fix
// before jest.spyOn(obj, mathodName); // typo -> undefined // after jest.spyOn(obj, 'methodName');
Defensive patterns
Strategy: validation
Validate before calling
if (methodKey == null) {
throw new TypeError('spyOn requires a property name');
}
jest.spyOn(obj, methodKey); Type guard
const hasMethodName = (k: unknown): k is string | number | symbol => k != null;
Prevention
- Pass property names as string literals where possible.
- Run TypeScript so an undefined key variable is flagged.
- Add a lint rule banning spyOn with fewer than 2 arguments.
When it happens
Trigger: jest.spyOn(obj); jest.spyOn(obj, undefined); jest.spyOn(obj, methodName) where methodName is an undefined variable.
Common situations: Refactor removed the method but left the spyOn call; a typo in the variable name; a computed key built from an undefined value; forgetting the second argument entirely.
Related errors
- Cannot replace the ` ` property because it is a function…
- Cannot spy on the ` ` property because it is not a…
- Cannot spy on the property because it is not a function…
- Cannot use spyOn on a primitive value;
- Property ` ` does not exist in the provided object
AI-assisted analysis of jestjs/jest@8e6d128e4a (2026-08-10).
Data as JSON: /api/errors/5a142810594a690a.
Report an issue: GitHub.
Appendix: source
Thrown at packages/jest-mock/src/index.ts:1286
methodKey: K,
): V extends ClassLike | FunctionLike ? Spied<V> : never;
spyOn<T extends object>(
object: T,
methodKey: keyof T,
accessType?: 'get' | 'set',
): MockInstance {
if (
object == null ||
(typeof object !== 'object' && typeof object !== 'function')
) {
throw new Error(
`Cannot use spyOn on a primitive value; ${this._typeOf(object)} given`,
);
}
if (methodKey == null) {
throw new Error('No property name supplied');
}
if (accessType) {
return this._spyOnProperty(object, methodKey, accessType);
}
const original = object[methodKey];
if (!original) {
throw new Error(
`Property \`${String(
methodKey,
)}\` does not exist in the provided object`,
);
}
if (!this.isMockFunction(original)) {
if (typeof original !== 'function') {View on GitHub (pinned to 8e6d128e4a)