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:
Steve Gravrock
2019-10-08 22:57:07 -07:00
committed by Steve Gravrock
parent dec67bd535
commit 1f23f1e4d2
46 changed files with 546 additions and 401 deletions
@@ -2,7 +2,7 @@ describe('#toBeRejectedWithError', function () {
it('passes when Error type matches', function () {
jasmine.getEnv().requirePromises();
var matchersUtil = new jasmineUnderTest.MatchersUtil(),
var matchersUtil = new jasmineUnderTest.MatchersUtil({pp: new jasmineUnderTest.makePrettyPrinter()}),
matcher = jasmineUnderTest.asyncMatchers.toBeRejectedWithError(matchersUtil),
actual = Promise.reject(new TypeError('foo'));
@@ -17,7 +17,7 @@ describe('#toBeRejectedWithError', function () {
it('passes when Error type and message matches', function () {
jasmine.getEnv().requirePromises();
var matchersUtil = new jasmineUnderTest.MatchersUtil(),
var matchersUtil = new jasmineUnderTest.MatchersUtil({pp: new jasmineUnderTest.makePrettyPrinter()}),
matcher = jasmineUnderTest.asyncMatchers.toBeRejectedWithError(matchersUtil),
actual = Promise.reject(new TypeError('foo'));
@@ -32,7 +32,7 @@ describe('#toBeRejectedWithError', function () {
it('passes when Error matches and is exactly Error', function() {
jasmine.getEnv().requirePromises();
var matchersUtil = new jasmineUnderTest.MatchersUtil(),
var matchersUtil = new jasmineUnderTest.MatchersUtil({pp: new jasmineUnderTest.makePrettyPrinter()}),
matcher = jasmineUnderTest.asyncMatchers.toBeRejectedWithError(matchersUtil),
actual = Promise.reject(new Error());
@@ -48,7 +48,7 @@ describe('#toBeRejectedWithError', function () {
it('passes when Error message matches a string', function () {
jasmine.getEnv().requirePromises();
var matchersUtil = new jasmineUnderTest.MatchersUtil(),
var matchersUtil = new jasmineUnderTest.MatchersUtil({pp: new jasmineUnderTest.makePrettyPrinter()}),
matcher = jasmineUnderTest.asyncMatchers.toBeRejectedWithError(matchersUtil),
actual = Promise.reject(new Error('foo'));
@@ -63,7 +63,7 @@ describe('#toBeRejectedWithError', function () {
it('passes when Error message matches a RegExp', function () {
jasmine.getEnv().requirePromises();
var matchersUtil = new jasmineUnderTest.MatchersUtil(),
var matchersUtil = new jasmineUnderTest.MatchersUtil({pp: new jasmineUnderTest.makePrettyPrinter()}),
matcher = jasmineUnderTest.asyncMatchers.toBeRejectedWithError(matchersUtil),
actual = Promise.reject(new Error('foo'));
@@ -78,7 +78,7 @@ describe('#toBeRejectedWithError', function () {
it('passes when Error message is empty', function () {
jasmine.getEnv().requirePromises();
var matchersUtil = new jasmineUnderTest.MatchersUtil(),
var matchersUtil = new jasmineUnderTest.MatchersUtil({pp: new jasmineUnderTest.makePrettyPrinter()}),
matcher = jasmineUnderTest.asyncMatchers.toBeRejectedWithError(matchersUtil),
actual = Promise.reject(new Error());
@@ -93,7 +93,7 @@ describe('#toBeRejectedWithError', function () {
it('passes when no arguments', function () {
jasmine.getEnv().requirePromises();
var matchersUtil = new jasmineUnderTest.MatchersUtil(),
var matchersUtil = new jasmineUnderTest.MatchersUtil({pp: new jasmineUnderTest.makePrettyPrinter()}),
matcher = jasmineUnderTest.asyncMatchers.toBeRejectedWithError(matchersUtil),
actual = Promise.reject(new Error());
@@ -108,7 +108,7 @@ describe('#toBeRejectedWithError', function () {
it('fails when resolved', function () {
jasmine.getEnv().requirePromises();
var matchersUtil = new jasmineUnderTest.MatchersUtil(),
var matchersUtil = new jasmineUnderTest.MatchersUtil({pp: new jasmineUnderTest.makePrettyPrinter()}),
matcher = jasmineUnderTest.asyncMatchers.toBeRejectedWithError(matchersUtil),
actual = Promise.resolve(new Error('foo'));
@@ -123,7 +123,7 @@ describe('#toBeRejectedWithError', function () {
it('fails when rejected with non Error type', function () {
jasmine.getEnv().requirePromises();
var matchersUtil = new jasmineUnderTest.MatchersUtil(),
var matchersUtil = new jasmineUnderTest.MatchersUtil({pp: new jasmineUnderTest.makePrettyPrinter()}),
matcher = jasmineUnderTest.asyncMatchers.toBeRejectedWithError(matchersUtil),
actual = Promise.reject('foo');
@@ -138,7 +138,7 @@ describe('#toBeRejectedWithError', function () {
it('fails when Error type mismatches', function () {
jasmine.getEnv().requirePromises();
var matchersUtil = new jasmineUnderTest.MatchersUtil(),
var matchersUtil = new jasmineUnderTest.MatchersUtil({pp: new jasmineUnderTest.makePrettyPrinter()}),
matcher = jasmineUnderTest.asyncMatchers.toBeRejectedWithError(matchersUtil),
actual = Promise.reject(new Error('foo'));
@@ -153,7 +153,7 @@ describe('#toBeRejectedWithError', function () {
it('fails when Error message mismatches', function () {
jasmine.getEnv().requirePromises();
var matchersUtil = new jasmineUnderTest.MatchersUtil(),
var matchersUtil = new jasmineUnderTest.MatchersUtil({pp: new jasmineUnderTest.makePrettyPrinter()}),
matcher = jasmineUnderTest.asyncMatchers.toBeRejectedWithError(matchersUtil),
actual = Promise.reject(new Error('foo'));
@@ -166,7 +166,7 @@ describe('#toBeRejectedWithError', function () {
});
it('fails if actual is not a promise', function() {
var matchersUtil = new jasmineUnderTest.MatchersUtil(),
var matchersUtil = new jasmineUnderTest.MatchersUtil({pp: new jasmineUnderTest.makePrettyPrinter()}),
matcher = jasmineUnderTest.asyncMatchers.toBeRejectedWithError(matchersUtil),
actual = 'not a promise';
@@ -26,7 +26,7 @@ describe('#toBeRejectedWith', function () {
it('should fail if the promise is rejected with a different value', function () {
jasmine.getEnv().requirePromises();
var matchersUtil = new jasmineUnderTest.MatchersUtil(),
var matchersUtil = new jasmineUnderTest.MatchersUtil({pp: jasmineUnderTest.makePrettyPrinter()}),
matcher = jasmineUnderTest.asyncMatchers.toBeRejectedWith(matchersUtil),
actual = Promise.reject('A Bad Apple');
@@ -41,7 +41,7 @@ describe('#toBeRejectedWith', function () {
it('should build its error correctly when negated', function () {
jasmine.getEnv().requirePromises();
var matchersUtil = new jasmineUnderTest.MatchersUtil(),
var matchersUtil = new jasmineUnderTest.MatchersUtil({pp: jasmineUnderTest.makePrettyPrinter()}),
matcher = jasmineUnderTest.asyncMatchers.toBeRejectedWith(matchersUtil),
actual = Promise.reject(true);
@@ -67,7 +67,7 @@ describe('#toBeRejectedWith', function () {
});
it('fails if actual is not a promise', function() {
var matchersUtil = new jasmineUnderTest.MatchersUtil(),
var matchersUtil = new jasmineUnderTest.MatchersUtil({pp: jasmineUnderTest.makePrettyPrinter()}),
matcher = jasmineUnderTest.asyncMatchers.toBeRejectedWith(matchersUtil),
actual = 'not a promise';
@@ -14,7 +14,7 @@ describe('#toBeResolvedTo', function() {
it('fails if the promise is rejected', function() {
jasmine.getEnv().requirePromises();
var matchersUtil = new jasmineUnderTest.MatchersUtil(),
var matchersUtil = new jasmineUnderTest.MatchersUtil({pp: new jasmineUnderTest.makePrettyPrinter()}),
matcher = jasmineUnderTest.asyncMatchers.toBeResolvedTo(matchersUtil),
actual = Promise.reject('AsyncExpectationSpec error');
@@ -29,7 +29,7 @@ describe('#toBeResolvedTo', function() {
it('fails if the promise is resolved to a different value', function() {
jasmine.getEnv().requirePromises();
var matchersUtil = new jasmineUnderTest.MatchersUtil(),
var matchersUtil = new jasmineUnderTest.MatchersUtil({pp: new jasmineUnderTest.makePrettyPrinter()}),
matcher = jasmineUnderTest.asyncMatchers.toBeResolvedTo(matchersUtil),
actual = Promise.resolve({foo: 17});
@@ -44,7 +44,7 @@ describe('#toBeResolvedTo', function() {
it('builds its message correctly when negated', function() {
jasmine.getEnv().requirePromises();
var matchersUtil = new jasmineUnderTest.MatchersUtil(),
var matchersUtil = new jasmineUnderTest.MatchersUtil({pp: new jasmineUnderTest.makePrettyPrinter()}),
matcher = jasmineUnderTest.asyncMatchers.toBeResolvedTo(matchersUtil),
actual = Promise.resolve(true);
@@ -60,7 +60,10 @@ describe('#toBeResolvedTo', function() {
jasmine.getEnv().requirePromises();
var customEqualityTesters = [function() { return true; }],
matchersUtil = new jasmineUnderTest.MatchersUtil({customTesters: customEqualityTesters}),
matchersUtil = new jasmineUnderTest.MatchersUtil({
customTesters: customEqualityTesters,
pp: jasmineUnderTest.makePrettyPrinter()
}),
matcher = jasmineUnderTest.asyncMatchers.toBeResolvedTo(matchersUtil),
actual = Promise.resolve('actual');
@@ -70,7 +73,7 @@ describe('#toBeResolvedTo', function() {
});
it('fails if actual is not a promise', function() {
var matchersUtil = new jasmineUnderTest.MatchersUtil(),
var matchersUtil = new jasmineUnderTest.MatchersUtil({pp: jasmineUnderTest.makePrettyPrinter()}),
matcher = jasmineUnderTest.asyncMatchers.toBeResolvedTo(matchersUtil),
actual = 'not a promise';
+31 -10
View File
@@ -1,4 +1,11 @@
describe("matchersUtil", function() {
it("exposes the injected pretty-printer as .pp", function() {
var pp = function() {},
matchersUtil = new jasmineUnderTest.MatchersUtil({pp: pp});
expect(matchersUtil.pp).toBe(pp);
});
describe("equals", function() {
it("passes for literals that are triple-equal", function() {
var matchersUtil = new jasmineUnderTest.MatchersUtil();
@@ -76,7 +83,7 @@ describe("matchersUtil", function() {
});
it("fails for Arrays that have different lengths", function() {
var matchersUtil = new jasmineUnderTest.MatchersUtil();
matchersUtil = new jasmineUnderTest.MatchersUtil();
expect(matchersUtil.equals([1, 2], [1, 2, 3])).toBe(false);
});
@@ -392,7 +399,7 @@ describe("matchersUtil", function() {
it("passes when a custom equality matcher passed to the constructor returns true", function() {
var tester = function(a, b) { return true; },
matchersUtil = new jasmineUnderTest.MatchersUtil({customTesters: [tester]});
matchersUtil = new jasmineUnderTest.MatchersUtil({customTesters: [tester], pp: function() {}});
expect(matchersUtil.equals(1, 2)).toBe(true);
});
@@ -416,7 +423,7 @@ describe("matchersUtil", function() {
var tester = function(a, b) { return jasmine.undefined; };
it("passes for two empty Objects", function () {
var matchersUtil = new jasmineUnderTest.MatchersUtil({customTesters: [tester]});
var matchersUtil = new jasmineUnderTest.MatchersUtil({customTesters: [tester], pp: function() {}});
expect(matchersUtil.equals({}, {})).toBe(true);
});
});
@@ -431,7 +438,7 @@ describe("matchersUtil", function() {
it("fails for equivalents when a custom equality matcher passed to the constructor returns false", function() {
var tester = function(a, b) { return false; },
matchersUtil = new jasmineUnderTest.MatchersUtil({customTesters: [tester]});
matchersUtil = new jasmineUnderTest.MatchersUtil({customTesters: [tester], pp: function() {}});
expect(matchersUtil.equals(1, 1)).toBe(false);
});
@@ -449,7 +456,7 @@ describe("matchersUtil", function() {
it("passes for an asymmetric equality tester that returns true when a custom equality tester passed to the constructor return false", function() {
var asymmetricTester = { asymmetricMatch: function(other) { return true; } },
symmetricTester = function(a, b) { return false; },
matchersUtil = new jasmineUnderTest.MatchersUtil({customTesters: [symmetricTester()]});
matchersUtil = new jasmineUnderTest.MatchersUtil({customTesters: [symmetricTester()], pp: function() {}});
expect(matchersUtil.equals(asymmetricTester, true)).toBe(true);
expect(matchersUtil.equals(true, asymmetricTester)).toBe(true);
@@ -475,7 +482,7 @@ describe("matchersUtil", function() {
it("is both a matchersUtil and the custom equality testers passed to the constructor", function() {
var asymmetricTester = jasmine.createSpyObj('tester', ['asymmetricMatch']),
symmetricTester = function() { } ,
matchersUtil = new jasmineUnderTest.MatchersUtil({customTesters: [symmetricTester]}),
matchersUtil = new jasmineUnderTest.MatchersUtil({customTesters: [symmetricTester], pp: function() {}}),
shim;
matchersUtil.equals(true, asymmetricTester);
@@ -783,7 +790,7 @@ describe("matchersUtil", function() {
it("uses custom equality testers if passed to the constructor and actual is an Array", function() {
var customTester = function(a, b) {return true;},
matchersUtil = new jasmineUnderTest.MatchersUtil({customTesters: [customTester]});
matchersUtil = new jasmineUnderTest.MatchersUtil({customTesters: [customTester], pp: function() {}});
expect(matchersUtil.contains([1, 2], 3)).toBe(true);
});
@@ -838,7 +845,8 @@ describe("matchersUtil", function() {
it("builds an English sentence for a failure case", function() {
var actual = "foo",
name = "toBar",
matchersUtil = new jasmineUnderTest.MatchersUtil(),
pp = jasmineUnderTest.makePrettyPrinter(),
matchersUtil = new jasmineUnderTest.MatchersUtil({pp: pp}),
message = matchersUtil.buildFailureMessage(name, false, actual);
expect(message).toEqual("Expected 'foo' to bar.");
@@ -848,7 +856,8 @@ describe("matchersUtil", function() {
var actual = "foo",
name = "toBar",
isNot = true,
matchersUtil = new jasmineUnderTest.MatchersUtil(),
pp = jasmineUnderTest.makePrettyPrinter(),
matchersUtil = new jasmineUnderTest.MatchersUtil({pp: pp}),
message = message = matchersUtil.buildFailureMessage(name, isNot, actual);
expect(message).toEqual("Expected 'foo' not to bar.");
@@ -857,10 +866,22 @@ describe("matchersUtil", function() {
it("builds an English sentence for an arbitrary array of expected arguments", function() {
var actual = "foo",
name = "toBar",
matchersUtil = new jasmineUnderTest.MatchersUtil(),
pp = jasmineUnderTest.makePrettyPrinter(),
matchersUtil = new jasmineUnderTest.MatchersUtil({pp: pp}),
message = matchersUtil.buildFailureMessage(name, false, actual, "quux", "corge");
expect(message).toEqual("Expected 'foo' to bar 'quux', 'corge'.");
});
it("uses the injected pretty-printer to format the expected", function() {
var actual = "foo",
name = "toBar",
isNot = false,
pp = function(value) { return '<' + value + '>'; },
matchersUtil = new jasmineUnderTest.MatchersUtil({pp: pp}),
message = message = matchersUtil.buildFailureMessage(name, isNot, actual);
expect(message).toEqual("Expected <foo> to bar.");
});
});
});
+9 -3
View File
@@ -10,7 +10,9 @@ describe('toBeInstanceOf', function() {
});
it('passes for NaN', function() {
var matcher = jasmineUnderTest.matchers.toBeInstanceOf();
var matcher = jasmineUnderTest.matchers.toBeInstanceOf({
pp: jasmineUnderTest.makePrettyPrinter()
});
var result = matcher.compare(NaN, Number);
expect(result).toEqual({
pass: true,
@@ -156,7 +158,9 @@ describe('toBeInstanceOf', function() {
it('passes for objects with no constructor', function() {
var object = Object.create(null);
var matcher = jasmineUnderTest.matchers.toBeInstanceOf();
var matcher = jasmineUnderTest.matchers.toBeInstanceOf({
pp: jasmineUnderTest.makePrettyPrinter()
});
var result = matcher.compare(object, Object);
expect(result).toEqual({
pass: true,
@@ -219,7 +223,9 @@ describe('toBeInstanceOf', function() {
});
it('raises an error if missing an expected value', function() {
var matcher = jasmineUnderTest.matchers.toBeInstanceOf();
var matcher = jasmineUnderTest.matchers.toBeInstanceOf({
pp: jasmineUnderTest.makePrettyPrinter()
});
expect(function() {
matcher.compare({}, undefined);
}).toThrowError('<toBeInstanceOf> : Expected value is not a constructor function\n' +
+3 -1
View File
@@ -29,7 +29,9 @@ describe("toBeNaN", function() {
});
it("has a custom message on failure", function() {
var matcher = jasmineUnderTest.matchers.toBeNaN(),
var matcher = jasmineUnderTest.matchers.toBeNaN({
pp: jasmineUnderTest.makePrettyPrinter()
}),
result = matcher.compare(0);
expect(result.message()).toEqual("Expected 0 to be NaN.");
@@ -14,7 +14,9 @@ describe("toBeNegativeInfinity", function() {
});
it("has a custom message on failure", function() {
var matcher = jasmineUnderTest.matchers.toBeNegativeInfinity(),
var matcher = jasmineUnderTest.matchers.toBeNegativeInfinity({
pp: jasmineUnderTest.makePrettyPrinter()
}),
result = matcher.compare(0);
expect(result.message()).toEqual("Expected 0 to be -Infinity.")
@@ -14,7 +14,9 @@ describe("toBePositiveInfinity", function() {
});
it("has a custom message on failure", function() {
var matcher = jasmineUnderTest.matchers.toBePositiveInfinity(),
var matcher = jasmineUnderTest.matchers.toBePositiveInfinity({
pp: jasmineUnderTest.makePrettyPrinter()
}),
result = matcher.compare(0);
expect(result.message()).toEqual("Expected 0 to be Infinity.")
+4 -4
View File
@@ -9,7 +9,7 @@ describe("toBe", function() {
});
it("passes with a custom message when expected is an array", function() {
var util = new jasmineUnderTest.MatchersUtil(),
var util = new jasmineUnderTest.MatchersUtil({pp: jasmineUnderTest.makePrettyPrinter()}),
matcher = jasmineUnderTest.matchers.toBe(util),
result,
array = [1];
@@ -20,7 +20,7 @@ describe("toBe", function() {
});
it("passes with a custom message when expected is an object", function() {
var util = new jasmineUnderTest.MatchersUtil(),
var util = new jasmineUnderTest.MatchersUtil({pp: jasmineUnderTest.makePrettyPrinter()}),
matcher = jasmineUnderTest.matchers.toBe(util),
result,
obj = {foo: "bar"};
@@ -41,7 +41,7 @@ describe("toBe", function() {
});
it("fails with a custom message when expected is an array", function() {
var util = new jasmineUnderTest.MatchersUtil(),
var util = new jasmineUnderTest.MatchersUtil({pp: jasmineUnderTest.makePrettyPrinter()}),
matcher = jasmineUnderTest.matchers.toBe(util),
result;
@@ -51,7 +51,7 @@ describe("toBe", function() {
});
it("fails with a custom message when expected is an object", function() {
var util = new jasmineUnderTest.MatchersUtil(),
var util = new jasmineUnderTest.MatchersUtil({pp: jasmineUnderTest.makePrettyPrinter()}),
matcher = jasmineUnderTest.matchers.toBe(util),
result;
+3 -3
View File
@@ -2,7 +2,9 @@ describe("toEqual", function() {
"use strict";
function compareEquals(actual, expected) {
var util = new jasmineUnderTest.MatchersUtil(),
var util = new jasmineUnderTest.MatchersUtil({
pp: jasmineUnderTest.makePrettyPrinter()
}),
matcher = jasmineUnderTest.matchers.toEqual(util);
var result = matcher.compare(actual, expected);
@@ -103,8 +105,6 @@ describe("toEqual", function() {
" g: 3\n" +
"Expected $.x not to have properties\n" +
" f: 4";
expect(compareEquals(actual, expected).message).toEqual(message);
});
it("reports extra and missing properties of the root-level object", function() {
@@ -1,6 +1,8 @@
describe("toHaveBeenCalledBefore", function() {
it("throws an exception when the actual is not a spy", function() {
var matcher = jasmineUnderTest.matchers.toHaveBeenCalledBefore(),
var matcher = jasmineUnderTest.matchers.toHaveBeenCalledBefore({
pp: jasmineUnderTest.makePrettyPrinter()
}),
fn = function() {},
secondSpy = new jasmineUnderTest.Env().createSpy('second spy');
@@ -8,7 +10,9 @@ describe("toHaveBeenCalledBefore", function() {
});
it("throws an exception when the expected is not a spy", function() {
var matcher = jasmineUnderTest.matchers.toHaveBeenCalledBefore(),
var matcher = jasmineUnderTest.matchers.toHaveBeenCalledBefore({
pp: jasmineUnderTest.makePrettyPrinter()
}),
firstSpy = new jasmineUnderTest.Env().createSpy('first spy'),
fn = function() {};
+3 -1
View File
@@ -21,7 +21,9 @@ describe("toHaveBeenCalled", function() {
});
it("throws an exception when the actual is not a spy", function() {
var matcher = jasmineUnderTest.matchers.toHaveBeenCalled(),
var matcher = jasmineUnderTest.matchers.toHaveBeenCalled({
pp: jasmineUnderTest.makePrettyPrinter()
}),
fn = function() {};
expect(function() { matcher.compare(fn) }).toThrowError(Error, /Expected a spy, but got Function./);
@@ -49,7 +49,9 @@ describe("toHaveBeenCalledTimes", function() {
});
it("throws an exception when the actual is not a spy", function() {
var matcher = jasmineUnderTest.matchers.toHaveBeenCalledTimes(),
var matcher = jasmineUnderTest.matchers.toHaveBeenCalledTimes({
pp: jasmineUnderTest.makePrettyPrinter()
}),
fn = function() {};
expect(function() {
+10 -5
View File
@@ -2,7 +2,8 @@ describe("toHaveBeenCalledWith", function() {
it("passes when the actual was called with matching parameters", function() {
var util = {
contains: jasmine.createSpy('delegated-contains').and.returnValue(true)
contains: jasmine.createSpy('delegated-contains').and.returnValue(true),
pp: jasmineUnderTest.makePrettyPrinter()
},
matcher = jasmineUnderTest.matchers.toHaveBeenCalledWith(util),
calledSpy = new jasmineUnderTest.Env().createSpy('called-spy'),
@@ -29,7 +30,8 @@ describe("toHaveBeenCalledWith", function() {
it("fails when the actual was not called", function() {
var util = {
contains: jasmine.createSpy('delegated-contains').and.returnValue(false)
contains: jasmine.createSpy('delegated-contains').and.returnValue(false),
pp: jasmineUnderTest.makePrettyPrinter()
},
matcher = jasmineUnderTest.matchers.toHaveBeenCalledWith(util),
uncalledSpy = new jasmineUnderTest.Env().createSpy('uncalled spy'),
@@ -41,7 +43,7 @@ describe("toHaveBeenCalledWith", function() {
});
it("fails when the actual was called with different parameters", function() {
var util = new jasmineUnderTest.MatchersUtil(),
var util = new jasmineUnderTest.MatchersUtil({pp: jasmineUnderTest.makePrettyPrinter()}),
matcher = jasmineUnderTest.matchers.toHaveBeenCalledWith(util),
calledSpy = new jasmineUnderTest.Env().createSpy('called spy'),
result;
@@ -71,8 +73,11 @@ describe("toHaveBeenCalledWith", function() {
});
it("throws an exception when the actual is not a spy", function() {
var matcher = jasmineUnderTest.matchers.toHaveBeenCalledWith(),
fn = function() {};
var matcher = jasmineUnderTest.matchers.toHaveBeenCalledWith({
pp: jasmineUnderTest.makePrettyPrinter()
}),
fn = function () {
};
expect(function() { matcher.compare(fn) }).toThrowError(/Expected a spy, but got Function./);
});
+3 -1
View File
@@ -27,7 +27,9 @@ describe('toHaveClass', function() {
});
it('throws an exception when actual is not a DOM element', function() {
var matcher = jasmineUnderTest.matchers.toHaveClass();
var matcher = jasmineUnderTest.matchers.toHaveClass({
pp: jasmineUnderTest.makePrettyPrinter()
});
expect(function() {
matcher.compare('x', 'foo');
+33 -16
View File
@@ -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");
},
+7 -3
View File
@@ -32,7 +32,9 @@ describe("toThrowMatching", function() {
});
it("fails with the correct message if thrown is a falsy value", function() {
var matcher = jasmineUnderTest.matchers.toThrowMatching(),
var matcher = jasmineUnderTest.matchers.toThrowMatching({
pp: jasmineUnderTest.makePrettyPrinter()
}),
fn = function() {
throw undefined;
},
@@ -58,8 +60,10 @@ describe("toThrowMatching", function() {
});
it("fails if the argument is a function that returns false when called with the error", function() {
var matcher = jasmineUnderTest.matchers.toThrowMatching(),
predicate = function(e) { return e.message === "oh no" },
var matcher = jasmineUnderTest.matchers.toThrowMatching({
pp: jasmineUnderTest.makePrettyPrinter()
}),
predicate = function(e) { return e.message === "oh no" },
fn = function() {
throw new TypeError("nope");
},
+11 -5
View File
@@ -24,7 +24,8 @@ describe("toThrow", function() {
it("passes if it throws but there is no expected", 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.toThrow(util),
fn = function() {
@@ -39,7 +40,9 @@ describe("toThrow", function() {
});
it("passes even if what is thrown is falsy", function() {
var matcher = jasmineUnderTest.matchers.toThrow(),
var matcher = jasmineUnderTest.matchers.toThrow({
pp: jasmineUnderTest.makePrettyPrinter()
}),
fn = function() {
throw undefined;
},
@@ -52,7 +55,8 @@ describe("toThrow", function() {
it("passes if what is thrown is equivalent to what is expected", 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.toThrow(util),
fn = function() {
@@ -68,7 +72,8 @@ describe("toThrow", function() {
it("fails if what is thrown is not equivalent to what is expected", 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.toThrow(util),
fn = function() {
@@ -84,7 +89,8 @@ describe("toThrow", function() {
it("fails if what is thrown is not equivalent to undefined", 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.toThrow(util),
fn = function() {