jestjs/jest · error · Error
${propertyName} is not declared configurable
Error message
${propertyName} is not declared configurable What it means
Thrown by `SpyRegistry._spyOnProperty` in spyRegistry.ts:178 when the descriptor's `configurable` flag is false. jasmine2 redefines the property with `Object.defineProperty`, which throws on non-configurable properties; this guard gives a clearer message first.
Source
Thrown at packages/jest-jasmine2/src/jasmine/spyRegistry.ts:178
}
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`),
);
}
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`),View on GitHub (pinned to f49721c78e)
Solutions
- Make the property configurable in production code (`Object.defineProperty(obj, 'p', { configurable: true, ... })`).
- Spy on the prototype if the instance property is non-configurable but the prototype property is configurable.
- Refactor to inject the dependency so you do not need to redefine a frozen property.
Example fix
// before spyOnProperty(frozenConfig, 'timeout', 'get') // non-configurable // after // make it configurable in the module under test, or inject the value spyOnProperty(Proto.prototype, 'timeout', 'get')
Defensive patterns
Strategy: validation
Validate before calling
const d = Object.getOwnPropertyDescriptor(obj, propertyName);
if (d && !d.configurable) { throw new Error(`${propertyName} is non-configurable`); }
spyOnProperty(obj, propertyName, 'get'); Type guard
const isConfigurable = (o: object, p: string): boolean => {
const d = Object.getOwnPropertyDescriptor(o, p);
return !d || Boolean(d.configurable);
}; Prevention
- Define test-relevant properties as configurable: true.
- Avoid Object.freeze/Object.seal on objects you need to spy on.
When it happens
Trigger: Spying on a property defined with `configurable: false`, a non-configurable built-in (e.g. `window.location` props), or an object sealed/frozen with `Object.seal`/`Object.freeze`.
Common situations: Frozen config objects; sealed singletons; TS `readonly` fields compiled non-configurable; trying to spy on host-provided non-configurable globals.
Related errors
- ${methodName} is not declared writable or has no setter
- could not find an object to spy upon for ${propertyName}
- No property name supplied
- ${propertyName} property does not exist
- Property ${propertyName} does not have access type ${accessT
AI-assisted analysis of jestjs/jest@f49721c78e (2026-08-03).
Data as JSON: /data/errors/47cddda507bbe05e.json.
Report an issue: GitHub.