diff --git a/spec/core/ObjectContainingSpec.js b/spec/core/ObjectContainingSpec.js index 235a08f1..1bbd4696 100644 --- a/spec/core/ObjectContainingSpec.js +++ b/spec/core/ObjectContainingSpec.js @@ -29,6 +29,19 @@ describe("ObjectContaining", function() { expect(containing.jasmineMatches({foo: "fooVal", bar: "barVal"})).toBe(false); }); + + it("mismatchValues parameter must return array with mismatched reason", function() { + var containing = new j$.ObjectContaining({foo: "other"}); + + var mismatchKeys = []; + var mismatchValues = []; + + containing.jasmineMatches({foo: "fooVal", bar: "barVal"}, mismatchKeys, mismatchValues); + + expect(mismatchValues.length).toBe(1); + + expect(mismatchValues[0]).toEqual("'foo' was 'fooVal' in actual, but was 'other' in expected."); + }); it("jasmineToString's itself", function() { var containing = new j$.ObjectContaining({}); diff --git a/src/core/ObjectContaining.js b/src/core/ObjectContaining.js index 90e999af..df6831e8 100644 --- a/src/core/ObjectContaining.js +++ b/src/core/ObjectContaining.js @@ -17,7 +17,7 @@ getJasmineRequireObj().ObjectContaining = function(j$) { mismatchKeys.push("expected has key '" + property + "', but missing from actual."); } else if (!j$.matchersUtil.equals(this.sample[property], other[property], mismatchKeys, mismatchValues)) { - mismatchValues.push("'" + property + "' was '" + (other[property] ? j$.util.htmlEscape(other[property].toString()) : other[property]) + "' in expected, but was '" + (this.sample[property] ? j$.util.htmlEscape(this.sample[property].toString()) : this.sample[property]) + "' in actual."); + 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."); } }