diff --git a/spec/core/ExceptionFormatterSpec.js b/spec/core/ExceptionFormatterSpec.js index c62e45c2..203be25c 100644 --- a/spec/core/ExceptionFormatterSpec.js +++ b/spec/core/ExceptionFormatterSpec.js @@ -41,8 +41,11 @@ describe("ExceptionFormatter", function() { describe("#stack", function() { it("formats stack traces from Webkit, Firefox or node.js", function() { + if (isIE()) { return; } + var error; - try { throw new Error("an error") } catch(e) { error = e; }; + try { throw new Error("an error") } catch(e) { error = e; } + expect(new j$.ExceptionFormatter().stack(error)).toMatch(/ExceptionFormatterSpec\.js.*\d+/) }); diff --git a/spec/core/ObjectContainingSpec.js b/spec/core/ObjectContainingSpec.js index 1bbd4696..673cb944 100644 --- a/spec/core/ObjectContainingSpec.js +++ b/spec/core/ObjectContainingSpec.js @@ -9,7 +9,9 @@ describe("ObjectContaining", function() { it("does not match an empty object actual", function() { var containing = new j$.ObjectContaining("foo"); - expect(containing.jasmineMatches({})).toBe(false); + expect(function() { + containing.jasmineMatches({}) + }).toThrowError(/not 'foo'/) }); it("matches when the key/value pair is present in the actual", function() { @@ -39,10 +41,21 @@ describe("ObjectContaining", function() { 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("adds keys in expected but not actual to the mismatchKeys parameter", function() { + var containing = new j$.ObjectContaining({foo: "fooVal"}); + + var mismatchKeys = []; + var mismatchValues = []; + + containing.jasmineMatches({bar: "barVal"}, mismatchKeys, mismatchValues); + + expect(mismatchKeys.length).toBe(1); + expect(mismatchKeys[0]).toEqual("expected has key 'foo', but missing from actual."); + }); + it("jasmineToString's itself", function() { var containing = new j$.ObjectContaining({}); diff --git a/spec/core/matchers/matchersUtilSpec.js b/spec/core/matchers/matchersUtilSpec.js index 276cbf5b..82f070ef 100644 --- a/spec/core/matchers/matchersUtilSpec.js +++ b/spec/core/matchers/matchersUtilSpec.js @@ -111,6 +111,8 @@ describe("matchersUtil", function() { }); it("passes for equivalent frozen objects (GitHub issue #266)", function() { + if (isIE(8)) { return; } + var a = { foo: 1 }, b = {foo: 1 }; diff --git a/spec/helpers/BrowserFlags.js b/spec/helpers/BrowserFlags.js new file mode 100644 index 00000000..9f9fb17a --- /dev/null +++ b/spec/helpers/BrowserFlags.js @@ -0,0 +1,8 @@ +function isIE(version) { + var userAgent = jasmine.getGlobal().navigator.userAgent; + if (!userAgent) { return; } + + var match = /MSIE ([0-9]{1,}[\.0-9]{0,})/.exec(userAgent); + + return match && version ? parseFloat(match[1]) === version : match; +} \ No newline at end of file diff --git a/src/core/ObjectContaining.js b/src/core/ObjectContaining.js index df6831e8..f080523b 100644 --- a/src/core/ObjectContaining.js +++ b/src/core/ObjectContaining.js @@ -5,6 +5,8 @@ getJasmineRequireObj().ObjectContaining = function(j$) { } ObjectContaining.prototype.jasmineMatches = function(other, mismatchKeys, mismatchValues) { + if (typeof(this.sample) !== "object") { throw new Error("You must provide an object to objectContaining, not '"+this.sample+"'."); } + mismatchKeys = mismatchKeys || []; mismatchValues = mismatchValues || []; @@ -16,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], mismatchKeys, mismatchValues)) { + else if (!j$.matchersUtil.equals(this.sample[property], other[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."); } }