Fix ObjectContaining to match recursively

matchersUtil.equals() does not expect a matcher as its first argument,
so send the "actual" value first and the "expected" value second.
This commit is contained in:
Chris Bandy
2014-03-01 17:01:05 -06:00
parent d7053612f5
commit 47884032ad
2 changed files with 7 additions and 1 deletions

View File

@@ -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);
});
});

View File

@@ -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.');
}
}