From 302e78f1dfd18e58f858f9a7376f38e6d35fe0bf Mon Sep 17 00:00:00 2001 From: Dan Finnie Date: Sun, 17 May 2015 02:21:26 -0400 Subject: [PATCH] Raise an error when jasmine.any() isn't passed a constructor --- spec/core/asymmetric_equality/AnySpec.js | 7 +++++++ src/core/asymmetric_equality/Any.js | 6 ++++++ 2 files changed, 13 insertions(+) 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; }