Inject a per-runable pretty printer into MatchersUtil
This will allow us to add support for custom object formatters, which will be a per-runable resource like custom matchers, by injecting them into the pretty-printer.
This commit is contained in:
committed by
Steve Gravrock
parent
dec67bd535
commit
1f23f1e4d2
@@ -54,7 +54,9 @@ describe("toThrowError", function() {
|
||||
});
|
||||
|
||||
it("fails if thrown is not an instanceof Error", function() {
|
||||
var matcher = jasmineUnderTest.matchers.toThrowError(),
|
||||
var matcher = jasmineUnderTest.matchers.toThrowError({
|
||||
pp: jasmineUnderTest.makePrettyPrinter()
|
||||
}),
|
||||
fn = function() {
|
||||
throw 4;
|
||||
},
|
||||
@@ -103,7 +105,9 @@ describe("toThrowError", function() {
|
||||
});
|
||||
|
||||
it("fails with the correct message if thrown is a falsy value", function() {
|
||||
var matcher = jasmineUnderTest.matchers.toThrowError(),
|
||||
var matcher = jasmineUnderTest.matchers.toThrowError({
|
||||
pp: jasmineUnderTest.makePrettyPrinter()
|
||||
}),
|
||||
fn = function() {
|
||||
throw undefined;
|
||||
},
|
||||
@@ -128,7 +132,9 @@ describe("toThrowError", function() {
|
||||
});
|
||||
|
||||
it("passes if thrown is an Error and the expected is the same message", function() {
|
||||
var matcher = jasmineUnderTest.matchers.toThrowError(),
|
||||
var matcher = jasmineUnderTest.matchers.toThrowError({
|
||||
pp: jasmineUnderTest.makePrettyPrinter()
|
||||
}),
|
||||
fn = function() {
|
||||
throw new Error("foo");
|
||||
},
|
||||
@@ -141,7 +147,9 @@ describe("toThrowError", function() {
|
||||
});
|
||||
|
||||
it("fails if thrown is an Error and the expected is not the same message", function() {
|
||||
var matcher = jasmineUnderTest.matchers.toThrowError(),
|
||||
var matcher = jasmineUnderTest.matchers.toThrowError({
|
||||
pp: jasmineUnderTest.makePrettyPrinter()
|
||||
}),
|
||||
fn = function() {
|
||||
throw new Error("foo");
|
||||
},
|
||||
@@ -154,7 +162,9 @@ describe("toThrowError", function() {
|
||||
});
|
||||
|
||||
it("passes if thrown is an Error and the expected is a RegExp that matches the message", function() {
|
||||
var matcher = jasmineUnderTest.matchers.toThrowError(),
|
||||
var matcher = jasmineUnderTest.matchers.toThrowError({
|
||||
pp: jasmineUnderTest.makePrettyPrinter()
|
||||
}),
|
||||
fn = function() {
|
||||
throw new Error("a long message");
|
||||
},
|
||||
@@ -167,7 +177,9 @@ describe("toThrowError", function() {
|
||||
});
|
||||
|
||||
it("fails if thrown is an Error and the expected is a RegExp that does not match the message", function() {
|
||||
var matcher = jasmineUnderTest.matchers.toThrowError(),
|
||||
var matcher = jasmineUnderTest.matchers.toThrowError({
|
||||
pp: jasmineUnderTest.makePrettyPrinter()
|
||||
}),
|
||||
fn = function() {
|
||||
throw new Error("a long message");
|
||||
},
|
||||
@@ -232,9 +244,10 @@ describe("toThrowError", function() {
|
||||
|
||||
it("passes if thrown is a type of Error and it is equal to the expected Error and message", function() {
|
||||
var util = {
|
||||
equals: jasmine.createSpy('delegated-equal').and.returnValue(true)
|
||||
equals: jasmine.createSpy('delegated-equal').and.returnValue(true),
|
||||
pp: jasmineUnderTest.makePrettyPrinter()
|
||||
},
|
||||
matcher = jasmineUnderTest.matchers.toThrowError(),
|
||||
matcher = jasmineUnderTest.matchers.toThrowError(util),
|
||||
fn = function() {
|
||||
throw new TypeError("foo");
|
||||
},
|
||||
@@ -248,9 +261,10 @@ describe("toThrowError", function() {
|
||||
|
||||
it("passes if thrown is a custom error that takes arguments and it is equal to the expected custom error and message", function() {
|
||||
var util = {
|
||||
equals: jasmine.createSpy('delegated-equal').and.returnValue(true)
|
||||
equals: jasmine.createSpy('delegated-equal').and.returnValue(true),
|
||||
pp: jasmineUnderTest.makePrettyPrinter()
|
||||
},
|
||||
matcher = jasmineUnderTest.matchers.toThrowError(),
|
||||
matcher = jasmineUnderTest.matchers.toThrowError(util),
|
||||
CustomError = function CustomError(arg) { this.message = arg.message },
|
||||
fn = function() {
|
||||
throw new CustomError({message: "foo"});
|
||||
@@ -267,9 +281,10 @@ describe("toThrowError", function() {
|
||||
|
||||
it("fails if thrown is a type of Error and the expected is a different Error", function() {
|
||||
var util = {
|
||||
equals: jasmine.createSpy('delegated-equal').and.returnValue(false)
|
||||
equals: jasmine.createSpy('delegated-equal').and.returnValue(false),
|
||||
pp: jasmineUnderTest.makePrettyPrinter()
|
||||
},
|
||||
matcher = jasmineUnderTest.matchers.toThrowError(),
|
||||
matcher = jasmineUnderTest.matchers.toThrowError(util),
|
||||
fn = function() {
|
||||
throw new TypeError("foo");
|
||||
},
|
||||
@@ -283,9 +298,10 @@ describe("toThrowError", function() {
|
||||
|
||||
it("passes if thrown is a type of Error and has the same type as the expected Error and the message matches the expected message", function() {
|
||||
var util = {
|
||||
equals: jasmine.createSpy('delegated-equal').and.returnValue(true)
|
||||
equals: jasmine.createSpy('delegated-equal').and.returnValue(true),
|
||||
pp: jasmineUnderTest.makePrettyPrinter()
|
||||
},
|
||||
matcher = jasmineUnderTest.matchers.toThrowError(),
|
||||
matcher = jasmineUnderTest.matchers.toThrowError(util),
|
||||
fn = function() {
|
||||
throw new TypeError("foo");
|
||||
},
|
||||
@@ -299,9 +315,10 @@ describe("toThrowError", function() {
|
||||
|
||||
it("fails if thrown is a type of Error and the expected is a different Error", function() {
|
||||
var util = {
|
||||
equals: jasmine.createSpy('delegated-equal').and.returnValue(false)
|
||||
equals: jasmine.createSpy('delegated-equal').and.returnValue(false),
|
||||
pp: jasmineUnderTest.makePrettyPrinter()
|
||||
},
|
||||
matcher = jasmineUnderTest.matchers.toThrowError(),
|
||||
matcher = jasmineUnderTest.matchers.toThrowError(util),
|
||||
fn = function() {
|
||||
throw new TypeError("foo");
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user