From b4b3ac25a157a4169988f7f17bb46200d58a2bef Mon Sep 17 00:00:00 2001 From: slackersoft Date: Tue, 16 Dec 2014 13:21:48 -0800 Subject: [PATCH] spyOn explicitly checks to see that a method name to spy on was passed. [finish #27689237] --- lib/jasmine-core/jasmine.js | 4 ++++ spec/core/SpyRegistrySpec.js | 9 +++++++++ src/core/SpyRegistry.js | 4 ++++ 3 files changed, 17 insertions(+) diff --git a/lib/jasmine-core/jasmine.js b/lib/jasmine-core/jasmine.js index 12ba55e3..fd653ebc 100644 --- a/lib/jasmine-core/jasmine.js +++ b/lib/jasmine-core/jasmine.js @@ -1864,6 +1864,10 @@ getJasmineRequireObj().SpyRegistry = function(j$) { throw new Error('spyOn could not find an object to spy upon for ' + methodName + '()'); } + if (j$.util.isUndefined(methodName)) { + throw new Error('No method name supplied'); + } + if (j$.util.isUndefined(obj[methodName])) { throw new Error(methodName + '() method does not exist'); } diff --git a/spec/core/SpyRegistrySpec.js b/spec/core/SpyRegistrySpec.js index 36dcf68c..f7930172 100644 --- a/spec/core/SpyRegistrySpec.js +++ b/spec/core/SpyRegistrySpec.js @@ -7,6 +7,15 @@ describe("SpyRegistry", function() { }).toThrowError(/could not find an object/); }); + it("checks that a method name was passed", function() { + var spyRegistry = new j$.SpyRegistry(), + subject = {}; + + expect(function() { + spyRegistry.spyOn(subject); + }).toThrowError(/No method name supplied/); + }); + it("checks for the existence of the method", function() { var spyRegistry = new j$.SpyRegistry(), subject = {}; diff --git a/src/core/SpyRegistry.js b/src/core/SpyRegistry.js index 776393ed..43f9edfe 100644 --- a/src/core/SpyRegistry.js +++ b/src/core/SpyRegistry.js @@ -9,6 +9,10 @@ getJasmineRequireObj().SpyRegistry = function(j$) { throw new Error('spyOn could not find an object to spy upon for ' + methodName + '()'); } + if (j$.util.isUndefined(methodName)) { + throw new Error('No method name supplied'); + } + if (j$.util.isUndefined(obj[methodName])) { throw new Error(methodName + '() method does not exist'); }