From ef3f127d270ccbbd6dde3fe161e0e85474f19369 Mon Sep 17 00:00:00 2001 From: Steve Gravrock Date: Sat, 28 Sep 2019 18:39:43 -0700 Subject: [PATCH] Fixed comparison between ObjectContaining and non-objects on IE --- lib/jasmine-core/jasmine.js | 3 ++- src/core/asymmetric_equality/ObjectContaining.js | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/jasmine-core/jasmine.js b/lib/jasmine-core/jasmine.js index b442632e..64365dd2 100644 --- a/lib/jasmine-core/jasmine.js +++ b/lib/jasmine-core/jasmine.js @@ -2495,7 +2495,7 @@ getJasmineRequireObj().ObjectContaining = function(j$) { } function hasProperty(obj, property) { - if (!obj) { + if (!obj || typeof(obj) !== 'object') { return false; } @@ -2508,6 +2508,7 @@ getJasmineRequireObj().ObjectContaining = function(j$) { ObjectContaining.prototype.asymmetricMatch = function(other, customTesters) { if (typeof(this.sample) !== 'object') { throw new Error('You must provide an object to objectContaining, not \''+this.sample+'\'.'); } + // TODO: This succeeds when sample is an empty object and other is a non-object, but should probably fail for (var property in this.sample) { if (!hasProperty(other, property) || diff --git a/src/core/asymmetric_equality/ObjectContaining.js b/src/core/asymmetric_equality/ObjectContaining.js index 9830fe90..d2da5c05 100644 --- a/src/core/asymmetric_equality/ObjectContaining.js +++ b/src/core/asymmetric_equality/ObjectContaining.js @@ -17,7 +17,7 @@ getJasmineRequireObj().ObjectContaining = function(j$) { } function hasProperty(obj, property) { - if (!obj) { + if (!obj || typeof(obj) !== 'object') { return false; } @@ -30,6 +30,7 @@ getJasmineRequireObj().ObjectContaining = function(j$) { ObjectContaining.prototype.asymmetricMatch = function(other, customTesters) { if (typeof(this.sample) !== 'object') { throw new Error('You must provide an object to objectContaining, not \''+this.sample+'\'.'); } + // TODO: This succeeds when sample is an empty object and other is a non-object, but should probably fail for (var property in this.sample) { if (!hasProperty(other, property) ||