Fixed objectContaining to not match when the expected is the empty object and the actual is a non-object
This commit is contained in:
@@ -2508,7 +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
|
||||
if (typeof(other) !== 'object') { return false; }
|
||||
|
||||
for (var property in this.sample) {
|
||||
if (!hasProperty(other, property) ||
|
||||
|
||||
@@ -1,9 +1,17 @@
|
||||
describe("ObjectContaining", function() {
|
||||
|
||||
it("matches any actual to an empty object", function() {
|
||||
it("matches any object actual to an empty object", function() {
|
||||
var containing = new jasmineUnderTest.ObjectContaining({});
|
||||
|
||||
expect(containing.asymmetricMatch("foo")).toBe(true);
|
||||
expect(containing.asymmetricMatch({foo: 1})).toBe(true);
|
||||
});
|
||||
|
||||
it("does not match when the actual is not an object", function() {
|
||||
var containing = new jasmineUnderTest.ObjectContaining({});
|
||||
|
||||
[1, true, undefined, "a string"].forEach(function(actual) {
|
||||
expect(containing.asymmetricMatch(actual)).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
it("does not match an empty object actual", function() {
|
||||
|
||||
@@ -30,7 +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
|
||||
if (typeof(other) !== 'object') { return false; }
|
||||
|
||||
for (var property in this.sample) {
|
||||
if (!hasProperty(other, property) ||
|
||||
|
||||
Reference in New Issue
Block a user