{"id":"3cb0554ce362ebc4","repo":"jestjs/jest","slug":"no-method-name-supplied","errorCode":null,"errorMessage":"No method name supplied","messagePattern":"No method name supplied","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/jest-jasmine2/src/jasmine/spyRegistry.ts","lineNumber":96,"sourceCode":"    this.allowRespy = function (allow) {\n      this.respy = allow;\n    };\n\n    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 {","sourceCodeStart":78,"sourceCodeEnd":114,"githubUrl":"https://github.com/jestjs/jest/blob/f49721c78e195558b40913977c9230f5b7f559d8/packages/jest-jasmine2/src/jasmine/spyRegistry.ts#L78-L114","documentation":"Thrown by `SpyRegistry.spyOn` in spyRegistry.ts:96 when `methodName === void 0`. The spy registry needs an explicit method name string to know which property to replace on the host object.","triggerScenarios":"Calling `spyOn(obj)` with only one argument, or `spyOn(obj, undefined)` / `spyOn(obj, someVar)` where `someVar` is undefined.","commonSituations":"Typo in a dynamic spy (`spyOn(obj, methodName)` with a typo'd variable); refactor that introduced an optional chain producing undefined; misremembering jasmine's `spyOn(obj, 'name')` arity.","solutions":["Supply the method name as a string literal: `spyOn(obj, 'methodName')`.","If the name is dynamic, assert it is a string before spying.","Double-check the call arity — `spyOn` requires exactly two positional args (object, name)."],"exampleFix":"// before\nspyOn(dateUtils)\n// after\nspyOn(dateUtils, 'formatDate')","handlingStrategy":"validation","validationCode":"if (typeof methodName !== 'string') { throw new TypeError('spyOn needs a method name'); }\nspyOn(obj, methodName);","typeGuard":"const isMethodName = (s: unknown): s is string => typeof s === 'string' && s.length > 0;","tryCatchPattern":null,"preventionTips":["Prefer string literals for method names over dynamic variables.","Remember spyOn arity: (object, methodName)."],"tags":["jasmine2","spy","spy-on","missing-argument"],"analyzedSha":"f49721c78e195558b40913977c9230f5b7f559d8","analyzedAt":"2026-08-03T20:16:28.571Z","schemaVersion":2}