diff --git a/lib/jasmine-core/jasmine.js b/lib/jasmine-core/jasmine.js index 312d591e..51f38310 100644 --- a/lib/jasmine-core/jasmine.js +++ b/lib/jasmine-core/jasmine.js @@ -2384,6 +2384,12 @@ getJasmineRequireObj().TreeProcessor = function() { getJasmineRequireObj().Any = function(j$) { function Any(expectedObject) { + if (typeof expectedObject === 'undefined') { + throw new TypeError( + 'jasmine.any() expects to be passed a constructor function. ' + + 'Please pass one or use jasmine.anything() to match any object.' + ); + } this.expectedObject = expectedObject; } diff --git a/spec/core/asymmetric_equality/AnySpec.js b/spec/core/asymmetric_equality/AnySpec.js index a1caaea5..c490741a 100644 --- a/spec/core/asymmetric_equality/AnySpec.js +++ b/spec/core/asymmetric_equality/AnySpec.js @@ -42,4 +42,11 @@ describe("Any", function() { expect(any.jasmineToString()).toEqual(''); }); + describe("when called without an argument", function() { + it("tells the user to pass a constructor or use jasmine.anything()", function() { + expect(function() { + new j$.Any(); + }).toThrowError(TypeError, /constructor.*anything/); + }); + }); }); diff --git a/src/core/asymmetric_equality/Any.js b/src/core/asymmetric_equality/Any.js index 7f597c83..c401159a 100644 --- a/src/core/asymmetric_equality/Any.js +++ b/src/core/asymmetric_equality/Any.js @@ -1,6 +1,12 @@ getJasmineRequireObj().Any = function(j$) { function Any(expectedObject) { + if (typeof expectedObject === 'undefined') { + throw new TypeError( + 'jasmine.any() expects to be passed a constructor function. ' + + 'Please pass one or use jasmine.anything() to match any object.' + ); + } this.expectedObject = expectedObject; }