{"id":"ef7c631181a6ccec","repo":"jestjs/jest","slug":"methodname-method-does-not-exist","errorCode":null,"errorMessage":"${methodName}() method does not exist","messagePattern":"(.+?)\\(\\) method does not exist","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/jest-jasmine2/src/jasmine/spyRegistry.ts","lineNumber":100,"sourceCode":"    this.spyOn = (obj, methodName, accessType) => {\n      if (accessType) {\n        return this._spyOnProperty(obj, methodName, accessType);\n      }\n\n      if (obj === void 0) {\n        throw new Error(\n          getErrorMsg(\n            `could not find an object to spy upon for ${methodName}()`,\n          ),\n        );\n      }\n\n      if (methodName === void 0) {\n        throw new Error(getErrorMsg('No method name supplied'));\n      }\n\n      if (obj[methodName] === void 0) {\n        throw new Error(getErrorMsg(`${methodName}() method does not exist`));\n      }\n\n      if (obj[methodName] && isSpy(obj[methodName])) {\n        if (this.respy) {\n          return obj[methodName];\n        } else {\n          throw new Error(\n            getErrorMsg(`${methodName} has already been spied upon`),\n          );\n        }\n      }\n\n      let descriptor;\n      try {\n        descriptor = Object.getOwnPropertyDescriptor(obj, methodName);\n      } catch {\n        // IE 8 doesn't support `definePropery` on non-DOM nodes\n      }","sourceCodeStart":82,"sourceCodeEnd":118,"githubUrl":"https://github.com/jestjs/jest/blob/f49721c78e195558b40913977c9230f5b7f559d8/packages/jest-jasmine2/src/jasmine/spyRegistry.ts#L82-L118","documentation":"Thrown by `SpyRegistry.spyOn` in spyRegistry.ts:100 when `obj[methodName] === void 0`. The host object exists but has no property by that name, so there is nothing to replace with a spy.","triggerScenarios":"Calling `spyOn(userService, 'fetchUser')` when the method is actually named `getUser`; spying on an instance method that only exists on the prototype and the instance does not expose it; the method was renamed/removed in a library upgrade.","commonSituations":"Renaming a source method without updating tests; mocking a method that lives on a different object (class vs instance); version mismatch where the dependency dropped or renamed the API.","solutions":["Verify the method name exists on the object: `console.log(typeof obj.methodName)`.","If the method is on the prototype, spy on the prototype: `spyOn(MyClass.prototype, 'method')`.","After a dependency upgrade, grep the new version for the method name to catch renames."],"exampleFix":"// before\nspyOn(userService, 'fetchUser')\n// after\nspyOn(userService, 'getUser')","handlingStrategy":"validation","validationCode":"if (typeof obj[methodName] !== 'function') { throw new Error(`${methodName} is not a method on obj`); }\nspyOn(obj, methodName);","typeGuard":"const hasMethod = (o: Record<string, any>, m: string): boolean =>\n  typeof o?.[m] === 'function';","tryCatchPattern":null,"preventionTips":["After dependency upgrades, grep the test suite for spyOn calls and verify names.","Spy on the prototype for inherited methods."],"tags":["jasmine2","spy","spy-on","missing-method"],"analyzedSha":"f49721c78e195558b40913977c9230f5b7f559d8","analyzedAt":"2026-08-03T20:16:28.571Z","schemaVersion":2}