Resolve remaining test issues

This commit is contained in:
Greg Cobb and JR Boyens
2013-07-22 11:57:47 -07:00
parent 61a1f93488
commit 8c1881053c
5 changed files with 32 additions and 4 deletions

View File

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

View File

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

View File

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

View File

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

View File

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