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) ||