Skip to content

Commit

Permalink
Fix ObjectContaining to match recursively
Browse files Browse the repository at this point in the history
matchersUtil.equals() does not expect a matcher as its first argument,
so send the "actual" value first and the "expected" value second.
  • Loading branch information
cbandy committed Mar 2, 2014
1 parent d705361 commit 4788403
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
6 changes: 6 additions & 0 deletions spec/core/ObjectContainingSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,4 +61,10 @@ describe("ObjectContaining", function() {

expect(containing.jasmineToString()).toMatch("<jasmine.objectContaining");
});

it("matches recursively", function() {
var containing = new j$.ObjectContaining({one: new j$.ObjectContaining({two: {}})});

expect(containing.jasmineMatches({one: {two: {}}})).toBe(true);
});
});
2 changes: 1 addition & 1 deletion src/core/ObjectContaining.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ getJasmineRequireObj().ObjectContaining = function(j$) {
if (!hasKey(other, property) && hasKey(this.sample, property)) {
mismatchKeys.push('expected has key \'' + property + '\', but missing from actual.');
}
else if (!j$.matchersUtil.equals(this.sample[property], other[property])) {
else if (!j$.matchersUtil.equals(other[property], this.sample[property])) {
mismatchValues.push('\'' + property + '\' was \'' + (other[property] ? j$.util.htmlEscape(other[property].toString()) : other[property]) + '\' in actual, but was \'' + (this.sample[property] ? j$.util.htmlEscape(this.sample[property].toString()) : this.sample[property]) + '\' in expected.');
}
}
Expand Down

0 comments on commit 4788403

Please sign in to comment.