From a63172f53fe2f3429a4b09920c1273ca703c7d4a Mon Sep 17 00:00:00 2001 From: Steve Gravrock Date: Wed, 29 Nov 2017 08:10:01 -0800 Subject: [PATCH] expect(null).toEqual(jasmine.any(Object)) no longer passes [Finishes #153181443] Fixes #1255. --- lib/jasmine-core/jasmine.js | 2 +- spec/core/asymmetric_equality/AnySpec.js | 7 +++++++ src/core/asymmetric_equality/Any.js | 2 +- 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/lib/jasmine-core/jasmine.js b/lib/jasmine-core/jasmine.js index a13696be..7377fba4 100644 --- a/lib/jasmine-core/jasmine.js +++ b/lib/jasmine-core/jasmine.js @@ -1589,7 +1589,7 @@ getJasmineRequireObj().Any = function(j$) { } if (this.expectedObject == Object) { - return typeof other == 'object'; + return other !== null && typeof other == 'object'; } if (this.expectedObject == Boolean) { diff --git a/spec/core/asymmetric_equality/AnySpec.js b/spec/core/asymmetric_equality/AnySpec.js index 44ffe6b8..1739ae6f 100644 --- a/spec/core/asymmetric_equality/AnySpec.js +++ b/spec/core/asymmetric_equality/AnySpec.js @@ -68,10 +68,17 @@ describe("Any", function() { expect(any.asymmetricMatch(new Thing())).toBe(true); }); + it("does not treat null as an Object", function() { + var any = new jasmineUnderTest.Any(Object); + + expect(any.asymmetricMatch(null)).toBe(false); + }); + it("jasmineToString's itself", function() { var any = new jasmineUnderTest.Any(Number); expect(any.jasmineToString()).toEqual(''); + expect(any.jasmineToString()).toEqual(''); }); describe("when called without an argument", function() { diff --git a/src/core/asymmetric_equality/Any.js b/src/core/asymmetric_equality/Any.js index 3f447529..bc185518 100644 --- a/src/core/asymmetric_equality/Any.js +++ b/src/core/asymmetric_equality/Any.js @@ -24,7 +24,7 @@ getJasmineRequireObj().Any = function(j$) { } if (this.expectedObject == Object) { - return typeof other == 'object'; + return other !== null && typeof other == 'object'; } if (this.expectedObject == Boolean) {