{"id":"5a142810594a690a","repo":"jestjs/jest","slug":"no-property-name-supplied-5a1428","errorCode":null,"errorMessage":"No property name supplied","messagePattern":"No property name supplied","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/jest-mock/src/index.ts","lineNumber":1286,"sourceCode":"    methodKey: K,\n  ): V extends ClassLike | FunctionLike ? Spied<V> : never;\n\n  spyOn<T extends object>(\n    object: T,\n    methodKey: keyof T,\n    accessType?: 'get' | 'set',\n  ): MockInstance {\n    if (\n      object == null ||\n      (typeof object !== 'object' && typeof object !== 'function')\n    ) {\n      throw new Error(\n        `Cannot use spyOn on a primitive value; ${this._typeOf(object)} given`,\n      );\n    }\n\n    if (methodKey == null) {\n      throw new Error('No property name supplied');\n    }\n\n    if (accessType) {\n      return this._spyOnProperty(object, methodKey, accessType);\n    }\n\n    const original = object[methodKey];\n\n    if (!original) {\n      throw new Error(\n        `Property \\`${String(\n          methodKey,\n        )}\\` does not exist in the provided object`,\n      );\n    }\n\n    if (!this.isMockFunction(original)) {\n      if (typeof original !== 'function') {","sourceCodeStart":1268,"sourceCodeEnd":1304,"githubUrl":"https://github.com/jestjs/jest/blob/f49721c78e195558b40913977c9230f5b7f559d8/packages/jest-mock/src/index.ts#L1268-L1304","documentation":"Thrown by jest.spyOn when the second argument (methodKey) is null or undefined. The guard is simply methodKey == null. Without a property name the mocker has nothing to look up on the descriptor, so it fails fast rather than silently installing a spy on a random slot.","triggerScenarios":"jest.spyOn(obj); (missing second arg); jest.spyOn(obj, undefined); jest.spyOn(obj, null); jest.spyOn(obj, maybeMethod) where maybeMethod is undefined because a lookup failed. TypeScript usually catches this at compile time, but JS callers and loosely-typed code do not.","commonSituations":"Refactor that introduced an optional method name computed at runtime that became undefined; passing an options object as the second argument by mistake; copy-paste of a spy call with the key removed.","solutions":["Provide the literal property name: jest.spyOn(obj, 'methodName').","If the name is dynamic, validate it is a non-null string before calling: if (!key) throw new Error('key missing').","Check that the variable holding the method key was actually assigned — log it before the call."],"exampleFix":"// before\njest.spyOn(logger); // no method name\n// after\njest.spyOn(logger, 'info');","handlingStrategy":"validation","validationCode":"if (methodKey == null) {\n  throw new Error('spyOn requires a method name as the second argument');\n}\njest.spyOn(obj, methodKey);","typeGuard":"const hasMethodName = (k: unknown): k is string | number | symbol =>\n  k != null;\n\nif (hasMethodName(methodKey)) {\n  jest.spyOn(obj, methodKey);\n}","tryCatchPattern":null,"preventionTips":["Always pass the method name as a string literal when possible.","For dynamic keys, assert non-null before the call.","Enable TypeScript's checks so missing args fail at compile time."],"tags":["jest-mock","spyon","argument-error","missing-argument"],"analyzedSha":"f49721c78e195558b40913977c9230f5b7f559d8","analyzedAt":"2026-08-03T20:16:28.571Z","schemaVersion":2}