Merge branch 'custom-object-formatters' into cof-merge-candidate
This commit is contained in:
@@ -1,47 +1,136 @@
|
||||
describe("DiffBuilder", function() {
|
||||
it("records the actual and expected objects", function() {
|
||||
describe("DiffBuilder", function () {
|
||||
it("records the actual and expected objects", function () {
|
||||
var diffBuilder = jasmineUnderTest.DiffBuilder();
|
||||
diffBuilder.record({x: 'actual'}, {x: 'expected'});
|
||||
diffBuilder.setRoots({x: 'actual'}, {x: 'expected'});
|
||||
diffBuilder.recordMismatch();
|
||||
|
||||
expect(diffBuilder.getMessage()).toEqual("Expected Object({ x: 'actual' }) to equal Object({ x: 'expected' }).");
|
||||
});
|
||||
|
||||
it("prints the path at which the difference was found", function() {
|
||||
it("prints the path at which the difference was found", function () {
|
||||
var diffBuilder = jasmineUnderTest.DiffBuilder();
|
||||
diffBuilder.setRoots({foo: {x: 'actual'}}, {foo: {x: 'expected'}});
|
||||
|
||||
diffBuilder.withPath('foo', function() {
|
||||
diffBuilder.record({x: 'actual'}, {x: 'expected'});
|
||||
diffBuilder.withPath('foo', function () {
|
||||
diffBuilder.recordMismatch();
|
||||
});
|
||||
|
||||
expect(diffBuilder.getMessage()).toEqual("Expected $.foo = Object({ x: 'actual' }) to equal Object({ x: 'expected' }).");
|
||||
});
|
||||
|
||||
it("prints multiple messages, separated by newlines", function() {
|
||||
it("prints multiple messages, separated by newlines", function () {
|
||||
var diffBuilder = jasmineUnderTest.DiffBuilder();
|
||||
diffBuilder.setRoots({foo: 1, bar: 3}, {foo: 2, bar: 4});
|
||||
|
||||
diffBuilder.withPath('foo', function() {
|
||||
diffBuilder.record(1, 2);
|
||||
diffBuilder.withPath('foo', function () {
|
||||
diffBuilder.recordMismatch();
|
||||
});
|
||||
diffBuilder.withPath('bar', function () {
|
||||
diffBuilder.recordMismatch();
|
||||
});
|
||||
|
||||
var message =
|
||||
"Expected $.foo = 1 to equal 2.\n" +
|
||||
"Expected 3 to equal 4.";
|
||||
"Expected $.bar = 3 to equal 4.";
|
||||
|
||||
diffBuilder.record(3, 4);
|
||||
expect(diffBuilder.getMessage()).toEqual(message);
|
||||
});
|
||||
|
||||
it("allows customization of the message", function() {
|
||||
it("allows customization of the message", function () {
|
||||
var diffBuilder = jasmineUnderTest.DiffBuilder();
|
||||
diffBuilder.setRoots({x: 'bar'}, {x: 'foo'});
|
||||
|
||||
function darthVaderFormatter(actual, expected, path) {
|
||||
return "I find your lack of " + expected + " disturbing. (was " + actual + ", at " + path + ")"
|
||||
}
|
||||
|
||||
diffBuilder.withPath('x', function() {
|
||||
diffBuilder.record('bar', 'foo', darthVaderFormatter);
|
||||
diffBuilder.withPath('x', function () {
|
||||
diffBuilder.recordMismatch(darthVaderFormatter);
|
||||
});
|
||||
|
||||
expect(diffBuilder.getMessage()).toEqual("I find your lack of foo disturbing. (was bar, at $.x)");
|
||||
});
|
||||
|
||||
it("uses the injected pretty-printer", function () {
|
||||
var prettyPrinter = function (val) {
|
||||
return '|' + val + '|';
|
||||
},
|
||||
diffBuilder = jasmineUnderTest.DiffBuilder({prettyPrinter: prettyPrinter});
|
||||
prettyPrinter.customFormat_ = function () {
|
||||
};
|
||||
|
||||
diffBuilder.setRoots({foo: 'actual'}, {foo: 'expected'});
|
||||
diffBuilder.withPath('foo', function () {
|
||||
diffBuilder.recordMismatch();
|
||||
});
|
||||
|
||||
expect(diffBuilder.getMessage()).toEqual("Expected $.foo = |actual| to equal |expected|.");
|
||||
});
|
||||
|
||||
it("passes the injected pretty-printer to the diff formatter", function () {
|
||||
var diffFormatter = jasmine.createSpy('diffFormatter'),
|
||||
prettyPrinter = function () {
|
||||
},
|
||||
diffBuilder = jasmineUnderTest.DiffBuilder({prettyPrinter: prettyPrinter});
|
||||
prettyPrinter.customFormat_ = function () {
|
||||
};
|
||||
|
||||
diffBuilder.setRoots({x: 'bar'}, {x: 'foo'});
|
||||
diffBuilder.withPath('x', function () {
|
||||
diffBuilder.recordMismatch(diffFormatter);
|
||||
});
|
||||
|
||||
diffBuilder.getMessage();
|
||||
|
||||
expect(diffFormatter).toHaveBeenCalledWith('bar', 'foo', jasmine.anything(), prettyPrinter);
|
||||
});
|
||||
|
||||
it("uses custom object formatters on leaf nodes", function() {
|
||||
var formatter = function(x) {
|
||||
if (typeof x === 'number') {
|
||||
return '[number:' + x + ']';
|
||||
}
|
||||
};
|
||||
prettyPrinter = jasmineUnderTest.makePrettyPrinter([formatter]);
|
||||
var diffBuilder = new jasmineUnderTest.DiffBuilder({prettyPrinter: prettyPrinter});
|
||||
|
||||
diffBuilder.setRoots(5, 4);
|
||||
diffBuilder.recordMismatch();
|
||||
|
||||
expect(diffBuilder.getMessage()).toEqual('Expected [number:5] to equal [number:4].');
|
||||
});
|
||||
|
||||
|
||||
it("uses custom object formatters on non leaf nodes", function () {
|
||||
var formatter = function (x) {
|
||||
if (x.hasOwnProperty('a')) {
|
||||
return '[thing with a=' + x.a + ', b=' + JSON.stringify(x.b) + ']';
|
||||
}
|
||||
};
|
||||
prettyPrinter = jasmineUnderTest.makePrettyPrinter([formatter]);
|
||||
var diffBuilder = new jasmineUnderTest.DiffBuilder({prettyPrinter: prettyPrinter});
|
||||
var expectedMsg = 'Expected $[0].foo = [thing with a=1, b={"x":42}] to equal [thing with a=1, b={"x":43}].\n' +
|
||||
"Expected $[0].bar = 'yes' to equal 'no'.";
|
||||
|
||||
diffBuilder.setRoots(
|
||||
[{foo: {a: 1, b: {x: 42}}, bar: 'yes'}],
|
||||
[{foo: {a: 1, b: {x: 43}}, bar: 'no'}]
|
||||
);
|
||||
|
||||
diffBuilder.withPath(0, function () {
|
||||
diffBuilder.withPath('foo', function () {
|
||||
diffBuilder.withPath('b', function () {
|
||||
diffBuilder.withPath('x', function () {
|
||||
diffBuilder.recordMismatch();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
diffBuilder.withPath('bar', function () {
|
||||
diffBuilder.recordMismatch();
|
||||
});
|
||||
});
|
||||
|
||||
expect(diffBuilder.getMessage()).toEqual(expectedMsg);
|
||||
});
|
||||
});
|
||||
|
||||
136
spec/core/matchers/MismatchTreeSpec.js
Normal file
136
spec/core/matchers/MismatchTreeSpec.js
Normal file
@@ -0,0 +1,136 @@
|
||||
describe('MismatchTree', function () {
|
||||
describe('#add', function () {
|
||||
describe('When the path is empty', function () {
|
||||
it('flags the root node as mismatched', function () {
|
||||
var tree = new jasmineUnderTest.MismatchTree();
|
||||
tree.add(new jasmineUnderTest.ObjectPath([]));
|
||||
expect(tree.isMismatch).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
describe('When the path is not empty', function () {
|
||||
it('flags the node as mismatched', function () {
|
||||
var tree = new jasmineUnderTest.MismatchTree();
|
||||
|
||||
tree.add(new jasmineUnderTest.ObjectPath(['a', 'b']));
|
||||
|
||||
expect(tree.child('a').child('b').isMismatch).toBe(true);
|
||||
});
|
||||
|
||||
it('does not flag ancestors as mismatched', function () {
|
||||
var tree = new jasmineUnderTest.MismatchTree();
|
||||
|
||||
tree.add(new jasmineUnderTest.ObjectPath(['a', 'b']));
|
||||
|
||||
expect(tree.isMismatch).toBe(false);
|
||||
expect(tree.child('a').isMismatch).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
it('stores the formatter on only the target node', function () {
|
||||
var tree = new jasmineUnderTest.MismatchTree();
|
||||
|
||||
tree.add(new jasmineUnderTest.ObjectPath(['a', 'b']), formatter);
|
||||
|
||||
expect(tree.formatter).toBeFalsy();
|
||||
expect(tree.child('a').formatter).toBeFalsy();
|
||||
expect(tree.child('a').child('b').formatter).toBe(formatter);
|
||||
});
|
||||
|
||||
it('stores the path to the node', function () {
|
||||
var tree = new jasmineUnderTest.MismatchTree();
|
||||
|
||||
tree.add(new jasmineUnderTest.ObjectPath(['a', 'b']), formatter);
|
||||
|
||||
expect(tree.child('a').child('b').path.components).toEqual(['a', 'b']);
|
||||
});
|
||||
});
|
||||
|
||||
describe('#traverse', function () {
|
||||
it('calls the callback for all nodes that are or contain mismatches', function () {
|
||||
var tree = new jasmineUnderTest.MismatchTree();
|
||||
tree.add(new jasmineUnderTest.ObjectPath(['a', 'b']), formatter);
|
||||
tree.add(new jasmineUnderTest.ObjectPath(['c']));
|
||||
var visit = jasmine.createSpy('visit').and.returnValue(true);
|
||||
|
||||
tree.traverse(visit);
|
||||
|
||||
expect(visit).toHaveBeenCalledWith(
|
||||
new jasmineUnderTest.ObjectPath([]), false, undefined
|
||||
);
|
||||
expect(visit).toHaveBeenCalledWith(
|
||||
new jasmineUnderTest.ObjectPath(['a']), false, undefined
|
||||
);
|
||||
expect(visit).toHaveBeenCalledWith(
|
||||
new jasmineUnderTest.ObjectPath(['a', 'b']), true, formatter
|
||||
);
|
||||
expect(visit).toHaveBeenCalledWith(
|
||||
new jasmineUnderTest.ObjectPath(['c']), true, undefined
|
||||
);
|
||||
});
|
||||
|
||||
it('does not call the callback if there are no mismatches', function () {
|
||||
var tree = new jasmineUnderTest.MismatchTree();
|
||||
var visit = jasmine.createSpy('visit');
|
||||
|
||||
tree.traverse(visit);
|
||||
|
||||
expect(visit).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('visits parents before children', function () {
|
||||
var tree = new jasmineUnderTest.MismatchTree();
|
||||
tree.add(new jasmineUnderTest.ObjectPath(['a', 'b']));
|
||||
var visited = [];
|
||||
|
||||
tree.traverse(function (path) {
|
||||
visited.push(path);
|
||||
return true;
|
||||
});
|
||||
|
||||
expect(visited).toEqual([
|
||||
new jasmineUnderTest.ObjectPath([]),
|
||||
new jasmineUnderTest.ObjectPath(['a']),
|
||||
new jasmineUnderTest.ObjectPath(['a', 'b'])
|
||||
]);
|
||||
});
|
||||
|
||||
it('visits children in the order they were recorded', function() {
|
||||
var tree = new jasmineUnderTest.MismatchTree();
|
||||
tree.add(new jasmineUnderTest.ObjectPath(['length']));
|
||||
tree.add(new jasmineUnderTest.ObjectPath([1]));
|
||||
var visited = [];
|
||||
|
||||
tree.traverse(function (path) {
|
||||
visited.push(path);
|
||||
return true;
|
||||
});
|
||||
|
||||
expect(visited).toEqual([
|
||||
new jasmineUnderTest.ObjectPath([]),
|
||||
new jasmineUnderTest.ObjectPath(['length']),
|
||||
new jasmineUnderTest.ObjectPath([1])
|
||||
]);
|
||||
});
|
||||
|
||||
it('does not visit children if the callback returns falsy', function() {
|
||||
var tree = new jasmineUnderTest.MismatchTree();
|
||||
tree.add(new jasmineUnderTest.ObjectPath(['a', 'b']));
|
||||
var visited = [];
|
||||
|
||||
tree.traverse(function (path) {
|
||||
visited.push(path);
|
||||
return path.depth() === 0;
|
||||
});
|
||||
|
||||
expect(visited).toEqual([
|
||||
new jasmineUnderTest.ObjectPath([]),
|
||||
new jasmineUnderTest.ObjectPath(['a'])
|
||||
]);
|
||||
});
|
||||
});
|
||||
|
||||
function formatter() {
|
||||
}
|
||||
|
||||
});
|
||||
@@ -1,13 +1,8 @@
|
||||
describe('NullDiffBuilder', function() {
|
||||
it('responds to withPath() by calling the passed function', function() {
|
||||
describe('NullDiffBuilder', function () {
|
||||
it('responds to withPath() by calling the passed function', function () {
|
||||
var spy = jasmine.createSpy('callback');
|
||||
jasmineUnderTest.NullDiffBuilder().withPath('does not matter', spy);
|
||||
expect(spy).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('responds to record()', function() {
|
||||
expect(function() {
|
||||
jasmineUnderTest.NullDiffBuilder().record('does not matter');
|
||||
}).not.toThrow();
|
||||
})
|
||||
});
|
||||
|
||||
@@ -39,5 +39,13 @@ describe('ObjectPath', function() {
|
||||
|
||||
expect(path.toString()).toEqual('$.foo');
|
||||
expect(root.toString()).toEqual('');
|
||||
})
|
||||
});
|
||||
|
||||
describe('#dereference', function() {
|
||||
it('returns the value corresponding to the path', function () {
|
||||
var path = new ObjectPath().add('foo').add(1).add('bar');
|
||||
var obj = {foo: ['', {bar: 42}]};
|
||||
expect(path.dereference(obj)).toEqual(42);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -2,7 +2,8 @@ describe('toBeRejected', function() {
|
||||
it('passes if the actual is rejected', function() {
|
||||
jasmine.getEnv().requirePromises();
|
||||
|
||||
var matcher = jasmineUnderTest.asyncMatchers.toBeRejected(jasmineUnderTest.matchersUtil),
|
||||
var matchersUtil = new jasmineUnderTest.MatchersUtil(),
|
||||
matcher = jasmineUnderTest.asyncMatchers.toBeRejected(matchersUtil),
|
||||
actual = Promise.reject('AsyncExpectationSpec rejection');
|
||||
|
||||
return matcher.compare(actual).then(function(result) {
|
||||
@@ -13,7 +14,8 @@ describe('toBeRejected', function() {
|
||||
it('fails if the actual is resolved', function() {
|
||||
jasmine.getEnv().requirePromises();
|
||||
|
||||
var matcher = jasmineUnderTest.asyncMatchers.toBeRejected(jasmineUnderTest.matchersUtil),
|
||||
var matchersUtil = new jasmineUnderTest.MatchersUtil(),
|
||||
matcher = jasmineUnderTest.asyncMatchers.toBeRejected(matchersUtil),
|
||||
actual = Promise.resolve();
|
||||
|
||||
return matcher.compare(actual).then(function(result) {
|
||||
@@ -22,7 +24,8 @@ describe('toBeRejected', function() {
|
||||
});
|
||||
|
||||
it('fails if actual is not a promise', function() {
|
||||
var matcher = jasmineUnderTest.asyncMatchers.toBeRejected(jasmineUnderTest.matchersUtil),
|
||||
var matchersUtil = new jasmineUnderTest.MatchersUtil(),
|
||||
matcher = jasmineUnderTest.asyncMatchers.toBeRejected(matchersUtil),
|
||||
actual = 'not a promise';
|
||||
|
||||
function f() {
|
||||
|
||||
@@ -2,7 +2,8 @@ describe('#toBeRejectedWithError', function () {
|
||||
it('passes when Error type matches', function () {
|
||||
jasmine.getEnv().requirePromises();
|
||||
|
||||
var matcher = jasmineUnderTest.asyncMatchers.toBeRejectedWithError(jasmineUnderTest.matchersUtil),
|
||||
var matchersUtil = new jasmineUnderTest.MatchersUtil({pp: new jasmineUnderTest.makePrettyPrinter()}),
|
||||
matcher = jasmineUnderTest.asyncMatchers.toBeRejectedWithError(matchersUtil),
|
||||
actual = Promise.reject(new TypeError('foo'));
|
||||
|
||||
return matcher.compare(actual, TypeError).then(function (result) {
|
||||
@@ -16,7 +17,8 @@ describe('#toBeRejectedWithError', function () {
|
||||
it('passes when Error type and message matches', function () {
|
||||
jasmine.getEnv().requirePromises();
|
||||
|
||||
var matcher = jasmineUnderTest.asyncMatchers.toBeRejectedWithError(jasmineUnderTest.matchersUtil),
|
||||
var matchersUtil = new jasmineUnderTest.MatchersUtil({pp: new jasmineUnderTest.makePrettyPrinter()}),
|
||||
matcher = jasmineUnderTest.asyncMatchers.toBeRejectedWithError(matchersUtil),
|
||||
actual = Promise.reject(new TypeError('foo'));
|
||||
|
||||
return matcher.compare(actual, TypeError, 'foo').then(function (result) {
|
||||
@@ -30,7 +32,8 @@ describe('#toBeRejectedWithError', function () {
|
||||
it('passes when Error matches and is exactly Error', function() {
|
||||
jasmine.getEnv().requirePromises();
|
||||
|
||||
var matcher = jasmineUnderTest.asyncMatchers.toBeRejectedWithError(jasmineUnderTest.matchersUtil),
|
||||
var matchersUtil = new jasmineUnderTest.MatchersUtil({pp: new jasmineUnderTest.makePrettyPrinter()}),
|
||||
matcher = jasmineUnderTest.asyncMatchers.toBeRejectedWithError(matchersUtil),
|
||||
actual = Promise.reject(new Error());
|
||||
|
||||
return matcher.compare(actual, Error).then(function (result) {
|
||||
@@ -45,7 +48,8 @@ describe('#toBeRejectedWithError', function () {
|
||||
it('passes when Error message matches a string', function () {
|
||||
jasmine.getEnv().requirePromises();
|
||||
|
||||
var matcher = jasmineUnderTest.asyncMatchers.toBeRejectedWithError(jasmineUnderTest.matchersUtil),
|
||||
var matchersUtil = new jasmineUnderTest.MatchersUtil({pp: new jasmineUnderTest.makePrettyPrinter()}),
|
||||
matcher = jasmineUnderTest.asyncMatchers.toBeRejectedWithError(matchersUtil),
|
||||
actual = Promise.reject(new Error('foo'));
|
||||
|
||||
return matcher.compare(actual, 'foo').then(function (result) {
|
||||
@@ -59,7 +63,8 @@ describe('#toBeRejectedWithError', function () {
|
||||
it('passes when Error message matches a RegExp', function () {
|
||||
jasmine.getEnv().requirePromises();
|
||||
|
||||
var matcher = jasmineUnderTest.asyncMatchers.toBeRejectedWithError(jasmineUnderTest.matchersUtil),
|
||||
var matchersUtil = new jasmineUnderTest.MatchersUtil({pp: new jasmineUnderTest.makePrettyPrinter()}),
|
||||
matcher = jasmineUnderTest.asyncMatchers.toBeRejectedWithError(matchersUtil),
|
||||
actual = Promise.reject(new Error('foo'));
|
||||
|
||||
return matcher.compare(actual, /foo/).then(function (result) {
|
||||
@@ -73,7 +78,8 @@ describe('#toBeRejectedWithError', function () {
|
||||
it('passes when Error message is empty', function () {
|
||||
jasmine.getEnv().requirePromises();
|
||||
|
||||
var matcher = jasmineUnderTest.asyncMatchers.toBeRejectedWithError(jasmineUnderTest.matchersUtil),
|
||||
var matchersUtil = new jasmineUnderTest.MatchersUtil({pp: new jasmineUnderTest.makePrettyPrinter()}),
|
||||
matcher = jasmineUnderTest.asyncMatchers.toBeRejectedWithError(matchersUtil),
|
||||
actual = Promise.reject(new Error());
|
||||
|
||||
return matcher.compare(actual, '').then(function (result) {
|
||||
@@ -87,7 +93,8 @@ describe('#toBeRejectedWithError', function () {
|
||||
it('passes when no arguments', function () {
|
||||
jasmine.getEnv().requirePromises();
|
||||
|
||||
var matcher = jasmineUnderTest.asyncMatchers.toBeRejectedWithError(jasmineUnderTest.matchersUtil),
|
||||
var matchersUtil = new jasmineUnderTest.MatchersUtil({pp: new jasmineUnderTest.makePrettyPrinter()}),
|
||||
matcher = jasmineUnderTest.asyncMatchers.toBeRejectedWithError(matchersUtil),
|
||||
actual = Promise.reject(new Error());
|
||||
|
||||
return matcher.compare(actual, void 0).then(function (result) {
|
||||
@@ -101,7 +108,8 @@ describe('#toBeRejectedWithError', function () {
|
||||
it('fails when resolved', function () {
|
||||
jasmine.getEnv().requirePromises();
|
||||
|
||||
var matcher = jasmineUnderTest.asyncMatchers.toBeRejectedWithError(jasmineUnderTest.matchersUtil),
|
||||
var matchersUtil = new jasmineUnderTest.MatchersUtil({pp: new jasmineUnderTest.makePrettyPrinter()}),
|
||||
matcher = jasmineUnderTest.asyncMatchers.toBeRejectedWithError(matchersUtil),
|
||||
actual = Promise.resolve(new Error('foo'));
|
||||
|
||||
return matcher.compare(actual, 'foo').then(function (result) {
|
||||
@@ -115,7 +123,8 @@ describe('#toBeRejectedWithError', function () {
|
||||
it('fails when rejected with non Error type', function () {
|
||||
jasmine.getEnv().requirePromises();
|
||||
|
||||
var matcher = jasmineUnderTest.asyncMatchers.toBeRejectedWithError(jasmineUnderTest.matchersUtil),
|
||||
var matchersUtil = new jasmineUnderTest.MatchersUtil({pp: new jasmineUnderTest.makePrettyPrinter()}),
|
||||
matcher = jasmineUnderTest.asyncMatchers.toBeRejectedWithError(matchersUtil),
|
||||
actual = Promise.reject('foo');
|
||||
|
||||
return matcher.compare(actual, 'foo').then(function (result) {
|
||||
@@ -129,7 +138,8 @@ describe('#toBeRejectedWithError', function () {
|
||||
it('fails when Error type mismatches', function () {
|
||||
jasmine.getEnv().requirePromises();
|
||||
|
||||
var matcher = jasmineUnderTest.asyncMatchers.toBeRejectedWithError(jasmineUnderTest.matchersUtil),
|
||||
var matchersUtil = new jasmineUnderTest.MatchersUtil({pp: new jasmineUnderTest.makePrettyPrinter()}),
|
||||
matcher = jasmineUnderTest.asyncMatchers.toBeRejectedWithError(matchersUtil),
|
||||
actual = Promise.reject(new Error('foo'));
|
||||
|
||||
return matcher.compare(actual, TypeError, 'foo').then(function (result) {
|
||||
@@ -143,7 +153,8 @@ describe('#toBeRejectedWithError', function () {
|
||||
it('fails when Error message mismatches', function () {
|
||||
jasmine.getEnv().requirePromises();
|
||||
|
||||
var matcher = jasmineUnderTest.asyncMatchers.toBeRejectedWithError(jasmineUnderTest.matchersUtil),
|
||||
var matchersUtil = new jasmineUnderTest.MatchersUtil({pp: new jasmineUnderTest.makePrettyPrinter()}),
|
||||
matcher = jasmineUnderTest.asyncMatchers.toBeRejectedWithError(matchersUtil),
|
||||
actual = Promise.reject(new Error('foo'));
|
||||
|
||||
return matcher.compare(actual, 'bar').then(function (result) {
|
||||
@@ -155,7 +166,8 @@ describe('#toBeRejectedWithError', function () {
|
||||
});
|
||||
|
||||
it('fails if actual is not a promise', function() {
|
||||
var matcher = jasmineUnderTest.asyncMatchers.toBeRejectedWithError(jasmineUnderTest.matchersUtil),
|
||||
var matchersUtil = new jasmineUnderTest.MatchersUtil({pp: new jasmineUnderTest.makePrettyPrinter()}),
|
||||
matcher = jasmineUnderTest.asyncMatchers.toBeRejectedWithError(matchersUtil),
|
||||
actual = 'not a promise';
|
||||
|
||||
function f() {
|
||||
|
||||
@@ -2,7 +2,8 @@ describe('#toBeRejectedWith', function () {
|
||||
it('should return true if the promise is rejected with the expected value', function () {
|
||||
jasmine.getEnv().requirePromises();
|
||||
|
||||
var matcher = jasmineUnderTest.asyncMatchers.toBeRejectedWith(jasmineUnderTest.matchersUtil),
|
||||
var matchersUtil = new jasmineUnderTest.MatchersUtil(),
|
||||
matcher = jasmineUnderTest.asyncMatchers.toBeRejectedWith(matchersUtil),
|
||||
actual = Promise.reject({error: 'PEBCAK'});
|
||||
|
||||
return matcher.compare(actual, {error: 'PEBCAK'}).then(function (result) {
|
||||
@@ -13,7 +14,8 @@ describe('#toBeRejectedWith', function () {
|
||||
it('should fail if the promise resolves', function () {
|
||||
jasmine.getEnv().requirePromises();
|
||||
|
||||
var matcher = jasmineUnderTest.asyncMatchers.toBeRejectedWith(jasmineUnderTest.matchersUtil),
|
||||
var matchersUtil = new jasmineUnderTest.MatchersUtil(),
|
||||
matcher = jasmineUnderTest.asyncMatchers.toBeRejectedWith(matchersUtil),
|
||||
actual = Promise.resolve();
|
||||
|
||||
return matcher.compare(actual, '').then(function (result) {
|
||||
@@ -24,7 +26,8 @@ describe('#toBeRejectedWith', function () {
|
||||
it('should fail if the promise is rejected with a different value', function () {
|
||||
jasmine.getEnv().requirePromises();
|
||||
|
||||
var matcher = jasmineUnderTest.asyncMatchers.toBeRejectedWith(jasmineUnderTest.matchersUtil),
|
||||
var matchersUtil = new jasmineUnderTest.MatchersUtil({pp: jasmineUnderTest.makePrettyPrinter()}),
|
||||
matcher = jasmineUnderTest.asyncMatchers.toBeRejectedWith(matchersUtil),
|
||||
actual = Promise.reject('A Bad Apple');
|
||||
|
||||
return matcher.compare(actual, 'Some Cool Thing').then(function (result) {
|
||||
@@ -38,7 +41,8 @@ describe('#toBeRejectedWith', function () {
|
||||
it('should build its error correctly when negated', function () {
|
||||
jasmine.getEnv().requirePromises();
|
||||
|
||||
var matcher = jasmineUnderTest.asyncMatchers.toBeRejectedWith(jasmineUnderTest.matchersUtil),
|
||||
var matchersUtil = new jasmineUnderTest.MatchersUtil({pp: jasmineUnderTest.makePrettyPrinter()}),
|
||||
matcher = jasmineUnderTest.asyncMatchers.toBeRejectedWith(matchersUtil),
|
||||
actual = Promise.reject(true);
|
||||
|
||||
return matcher.compare(actual, true).then(function (result) {
|
||||
@@ -53,7 +57,8 @@ describe('#toBeRejectedWith', function () {
|
||||
jasmine.getEnv().requirePromises();
|
||||
|
||||
var customEqualityTesters = [function() { return true; }],
|
||||
matcher = jasmineUnderTest.asyncMatchers.toBeRejectedWith(jasmineUnderTest.matchersUtil, customEqualityTesters),
|
||||
matchersUtil = new jasmineUnderTest.MatchersUtil({customTesters: customEqualityTesters}),
|
||||
matcher = jasmineUnderTest.asyncMatchers.toBeRejectedWith(matchersUtil),
|
||||
actual = Promise.reject('actual');
|
||||
|
||||
return matcher.compare(actual, 'expected').then(function(result) {
|
||||
@@ -62,7 +67,8 @@ describe('#toBeRejectedWith', function () {
|
||||
});
|
||||
|
||||
it('fails if actual is not a promise', function() {
|
||||
var matcher = jasmineUnderTest.asyncMatchers.toBeRejectedWith(jasmineUnderTest.matchersUtil),
|
||||
var matchersUtil = new jasmineUnderTest.MatchersUtil({pp: jasmineUnderTest.makePrettyPrinter()}),
|
||||
matcher = jasmineUnderTest.asyncMatchers.toBeRejectedWith(matchersUtil),
|
||||
actual = 'not a promise';
|
||||
|
||||
function f() {
|
||||
|
||||
@@ -2,7 +2,8 @@ describe('toBeResolved', function() {
|
||||
it('passes if the actual is resolved', function() {
|
||||
jasmine.getEnv().requirePromises();
|
||||
|
||||
var matcher = jasmineUnderTest.asyncMatchers.toBeResolved(jasmineUnderTest.matchersUtil),
|
||||
var matchersUtil = new jasmineUnderTest.MatchersUtil(),
|
||||
matcher = jasmineUnderTest.asyncMatchers.toBeResolved(matchersUtil),
|
||||
actual = Promise.resolve();
|
||||
|
||||
return matcher.compare(actual).then(function(result) {
|
||||
@@ -13,7 +14,8 @@ describe('toBeResolved', function() {
|
||||
it('fails if the actual is rejected', function() {
|
||||
jasmine.getEnv().requirePromises();
|
||||
|
||||
var matcher = jasmineUnderTest.asyncMatchers.toBeResolved(jasmineUnderTest.matchersUtil),
|
||||
var matchersUtil = new jasmineUnderTest.MatchersUtil(),
|
||||
matcher = jasmineUnderTest.asyncMatchers.toBeResolved(matchersUtil),
|
||||
actual = Promise.reject('AsyncExpectationSpec rejection');
|
||||
|
||||
return matcher.compare(actual).then(function(result) {
|
||||
@@ -22,7 +24,8 @@ describe('toBeResolved', function() {
|
||||
});
|
||||
|
||||
it('fails if actual is not a promise', function() {
|
||||
var matcher = jasmineUnderTest.asyncMatchers.toBeResolved(jasmineUnderTest.matchersUtil),
|
||||
var matchersUtil = new jasmineUnderTest.MatchersUtil(),
|
||||
matcher = jasmineUnderTest.asyncMatchers.toBeResolved(matchersUtil),
|
||||
actual = 'not a promise';
|
||||
|
||||
function f() {
|
||||
|
||||
@@ -2,7 +2,8 @@ describe('#toBeResolvedTo', function() {
|
||||
it('passes if the promise is resolved to the expected value', function() {
|
||||
jasmine.getEnv().requirePromises();
|
||||
|
||||
var matcher = jasmineUnderTest.asyncMatchers.toBeResolvedTo(jasmineUnderTest.matchersUtil),
|
||||
var matchersUtil = new jasmineUnderTest.MatchersUtil(),
|
||||
matcher = jasmineUnderTest.asyncMatchers.toBeResolvedTo(matchersUtil),
|
||||
actual = Promise.resolve({foo: 42});
|
||||
|
||||
return matcher.compare(actual, {foo: 42}).then(function(result) {
|
||||
@@ -13,7 +14,8 @@ describe('#toBeResolvedTo', function() {
|
||||
it('fails if the promise is rejected', function() {
|
||||
jasmine.getEnv().requirePromises();
|
||||
|
||||
var matcher = jasmineUnderTest.asyncMatchers.toBeResolvedTo(jasmineUnderTest.matchersUtil),
|
||||
var matchersUtil = new jasmineUnderTest.MatchersUtil({pp: new jasmineUnderTest.makePrettyPrinter()}),
|
||||
matcher = jasmineUnderTest.asyncMatchers.toBeResolvedTo(matchersUtil),
|
||||
actual = Promise.reject('AsyncExpectationSpec error');
|
||||
|
||||
return matcher.compare(actual, '').then(function(result) {
|
||||
@@ -27,7 +29,8 @@ describe('#toBeResolvedTo', function() {
|
||||
it('fails if the promise is resolved to a different value', function() {
|
||||
jasmine.getEnv().requirePromises();
|
||||
|
||||
var matcher = jasmineUnderTest.asyncMatchers.toBeResolvedTo(jasmineUnderTest.matchersUtil),
|
||||
var matchersUtil = new jasmineUnderTest.MatchersUtil({pp: new jasmineUnderTest.makePrettyPrinter()}),
|
||||
matcher = jasmineUnderTest.asyncMatchers.toBeResolvedTo(matchersUtil),
|
||||
actual = Promise.resolve({foo: 17});
|
||||
|
||||
return matcher.compare(actual, {foo: 42}).then(function(result) {
|
||||
@@ -41,7 +44,8 @@ describe('#toBeResolvedTo', function() {
|
||||
it('builds its message correctly when negated', function() {
|
||||
jasmine.getEnv().requirePromises();
|
||||
|
||||
var matcher = jasmineUnderTest.asyncMatchers.toBeResolvedTo(jasmineUnderTest.matchersUtil),
|
||||
var matchersUtil = new jasmineUnderTest.MatchersUtil({pp: new jasmineUnderTest.makePrettyPrinter()}),
|
||||
matcher = jasmineUnderTest.asyncMatchers.toBeResolvedTo(matchersUtil),
|
||||
actual = Promise.resolve(true);
|
||||
|
||||
return matcher.compare(actual, true).then(function(result) {
|
||||
@@ -56,7 +60,11 @@ describe('#toBeResolvedTo', function() {
|
||||
jasmine.getEnv().requirePromises();
|
||||
|
||||
var customEqualityTesters = [function() { return true; }],
|
||||
matcher = jasmineUnderTest.asyncMatchers.toBeResolvedTo(jasmineUnderTest.matchersUtil, customEqualityTesters),
|
||||
matchersUtil = new jasmineUnderTest.MatchersUtil({
|
||||
customTesters: customEqualityTesters,
|
||||
pp: jasmineUnderTest.makePrettyPrinter()
|
||||
}),
|
||||
matcher = jasmineUnderTest.asyncMatchers.toBeResolvedTo(matchersUtil),
|
||||
actual = Promise.resolve('actual');
|
||||
|
||||
return matcher.compare(actual, 'expected').then(function(result) {
|
||||
@@ -65,7 +73,8 @@ describe('#toBeResolvedTo', function() {
|
||||
});
|
||||
|
||||
it('fails if actual is not a promise', function() {
|
||||
var matcher = jasmineUnderTest.asyncMatchers.toBeResolvedTo(jasmineUnderTest.matchersUtil),
|
||||
var matchersUtil = new jasmineUnderTest.MatchersUtil({pp: jasmineUnderTest.makePrettyPrinter()}),
|
||||
matcher = jasmineUnderTest.asyncMatchers.toBeResolvedTo(matchersUtil),
|
||||
actual = 'not a promise';
|
||||
|
||||
function f() {
|
||||
|
||||
@@ -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() {
|
||||
describe('Properties', function() {
|
||||
var fc;
|
||||
@@ -72,178 +79,210 @@ describe("matchersUtil", function() {
|
||||
});
|
||||
|
||||
it("passes for literals that are triple-equal", function() {
|
||||
expect(jasmineUnderTest.matchersUtil.equals(null, null)).toBe(true);
|
||||
expect(jasmineUnderTest.matchersUtil.equals(void 0, void 0)).toBe(true);
|
||||
var matchersUtil = new jasmineUnderTest.MatchersUtil();
|
||||
expect(matchersUtil.equals(null, null)).toBe(true);
|
||||
expect(matchersUtil.equals(void 0, void 0)).toBe(true);
|
||||
});
|
||||
|
||||
it("fails for things that are not equivalent", function() {
|
||||
expect(jasmineUnderTest.matchersUtil.equals({a: "foo"}, 1)).toBe(false);
|
||||
var matchersUtil = new jasmineUnderTest.MatchersUtil();
|
||||
expect(matchersUtil.equals({a: "foo"}, 1)).toBe(false);
|
||||
});
|
||||
|
||||
it("passes for Strings that are equivalent", function() {
|
||||
expect(jasmineUnderTest.matchersUtil.equals("foo", "foo")).toBe(true);
|
||||
var matchersUtil = new jasmineUnderTest.MatchersUtil();
|
||||
expect(matchersUtil.equals("foo", "foo")).toBe(true);
|
||||
});
|
||||
|
||||
it("fails for Strings that are not equivalent", function() {
|
||||
expect(jasmineUnderTest.matchersUtil.equals("foo", "bar")).toBe(false);
|
||||
var matchersUtil = new jasmineUnderTest.MatchersUtil();
|
||||
expect(matchersUtil.equals("foo", "bar")).toBe(false);
|
||||
});
|
||||
|
||||
it("passes for Numbers that are equivalent", function() {
|
||||
expect(jasmineUnderTest.matchersUtil.equals(123, 123)).toBe(true);
|
||||
var matchersUtil = new jasmineUnderTest.MatchersUtil();
|
||||
expect(matchersUtil.equals(123, 123)).toBe(true);
|
||||
});
|
||||
|
||||
it("fails for Numbers that are not equivalent", function() {
|
||||
expect(jasmineUnderTest.matchersUtil.equals(123, 456)).toBe(false);
|
||||
var matchersUtil = new jasmineUnderTest.MatchersUtil();
|
||||
expect(matchersUtil.equals(123, 456)).toBe(false);
|
||||
});
|
||||
|
||||
it("passes for Dates that are equivalent", function() {
|
||||
expect(jasmineUnderTest.matchersUtil.equals(new Date("Jan 1, 1970"), new Date("Jan 1, 1970"))).toBe(true);
|
||||
var matchersUtil = new jasmineUnderTest.MatchersUtil();
|
||||
expect(matchersUtil.equals(new Date("Jan 1, 1970"), new Date("Jan 1, 1970"))).toBe(true);
|
||||
});
|
||||
|
||||
it("fails for Dates that are not equivalent", function() {
|
||||
expect(jasmineUnderTest.matchersUtil.equals(new Date("Jan 1, 1970"), new Date("Feb 3, 1991"))).toBe(false);
|
||||
var matchersUtil = new jasmineUnderTest.MatchersUtil();
|
||||
expect(matchersUtil.equals(new Date("Jan 1, 1970"), new Date("Feb 3, 1991"))).toBe(false);
|
||||
});
|
||||
|
||||
it("passes for Booleans that are equivalent", function() {
|
||||
expect(jasmineUnderTest.matchersUtil.equals(true, true)).toBe(true);
|
||||
var matchersUtil = new jasmineUnderTest.MatchersUtil();
|
||||
expect(matchersUtil.equals(true, true)).toBe(true);
|
||||
});
|
||||
|
||||
it("fails for Booleans that are not equivalent", function() {
|
||||
expect(jasmineUnderTest.matchersUtil.equals(true, false)).toBe(false);
|
||||
var matchersUtil = new jasmineUnderTest.MatchersUtil();
|
||||
expect(matchersUtil.equals(true, false)).toBe(false);
|
||||
});
|
||||
|
||||
it("passes for RegExps that are equivalent", function() {
|
||||
expect(jasmineUnderTest.matchersUtil.equals(/foo/, /foo/)).toBe(true);
|
||||
var matchersUtil = new jasmineUnderTest.MatchersUtil();
|
||||
expect(matchersUtil.equals(/foo/, /foo/)).toBe(true);
|
||||
});
|
||||
|
||||
it("fails for RegExps that are not equivalent", function() {
|
||||
expect(jasmineUnderTest.matchersUtil.equals(/foo/, /bar/)).toBe(false);
|
||||
expect(jasmineUnderTest.matchersUtil.equals(new RegExp("foo", "i"), new RegExp("foo"))).toBe(false);
|
||||
var matchersUtil = new jasmineUnderTest.MatchersUtil();
|
||||
expect(matchersUtil.equals(/foo/, /bar/)).toBe(false);
|
||||
expect(matchersUtil.equals(new RegExp("foo", "i"), new RegExp("foo"))).toBe(false);
|
||||
});
|
||||
|
||||
it("passes for Arrays that are equivalent", function() {
|
||||
expect(jasmineUnderTest.matchersUtil.equals([1, 2], [1, 2])).toBe(true);
|
||||
var matchersUtil = new jasmineUnderTest.MatchersUtil();
|
||||
expect(matchersUtil.equals([1, 2], [1, 2])).toBe(true);
|
||||
});
|
||||
|
||||
it("passes for Arrays that are equivalent, with elements added by changing length", function() {
|
||||
var foo = [];
|
||||
var foo = [],
|
||||
matchersUtil = new jasmineUnderTest.MatchersUtil();
|
||||
foo.length = 1;
|
||||
|
||||
expect(jasmineUnderTest.matchersUtil.equals(foo, [undefined])).toBe(true);
|
||||
expect(matchersUtil.equals(foo, [undefined])).toBe(true);
|
||||
});
|
||||
|
||||
it("fails for Arrays that have different lengths", function() {
|
||||
expect(jasmineUnderTest.matchersUtil.equals([1, 2], [1, 2, 3])).toBe(false);
|
||||
matchersUtil = new jasmineUnderTest.MatchersUtil();
|
||||
expect(matchersUtil.equals([1, 2], [1, 2, 3])).toBe(false);
|
||||
});
|
||||
|
||||
it("fails for Arrays that have different elements", function() {
|
||||
expect(jasmineUnderTest.matchersUtil.equals([1, 2, 3], [1, 5, 3])).toBe(false);
|
||||
var matchersUtil = new jasmineUnderTest.MatchersUtil();
|
||||
expect(matchersUtil.equals([1, 2, 3], [1, 5, 3])).toBe(false);
|
||||
});
|
||||
|
||||
it("fails for Arrays whose contents are equivalent, but have differing properties", function() {
|
||||
var one = [1,2,3],
|
||||
two = [1,2,3];
|
||||
two = [1,2,3],
|
||||
matchersUtil = new jasmineUnderTest.MatchersUtil();
|
||||
|
||||
one.foo = 'bar';
|
||||
two.foo = 'baz';
|
||||
|
||||
expect(jasmineUnderTest.matchersUtil.equals(one, two)).toBe(false);
|
||||
expect(matchersUtil.equals(one, two)).toBe(false);
|
||||
});
|
||||
|
||||
it("passes for Arrays with equivalent contents and properties", function() {
|
||||
var one = [1,2,3],
|
||||
two = [1,2,3];
|
||||
two = [1,2,3],
|
||||
matchersUtil = new jasmineUnderTest.MatchersUtil();
|
||||
|
||||
one.foo = 'bar';
|
||||
two.foo = 'bar';
|
||||
|
||||
expect(jasmineUnderTest.matchersUtil.equals(one, two)).toBe(true);
|
||||
expect(matchersUtil.equals(one, two)).toBe(true);
|
||||
});
|
||||
|
||||
it("passes for Errors that are the same type and have the same message", function() {
|
||||
expect(jasmineUnderTest.matchersUtil.equals(new Error("foo"), new Error("foo"))).toBe(true);
|
||||
var matchersUtil = new jasmineUnderTest.MatchersUtil();
|
||||
expect(matchersUtil.equals(new Error("foo"), new Error("foo"))).toBe(true);
|
||||
});
|
||||
|
||||
it("fails for Errors that are the same type and have different messages", function() {
|
||||
expect(jasmineUnderTest.matchersUtil.equals(new Error("foo"), new Error("bar"))).toBe(false);
|
||||
var matchersUtil = new jasmineUnderTest.MatchersUtil();
|
||||
expect(matchersUtil.equals(new Error("foo"), new Error("bar"))).toBe(false);
|
||||
});
|
||||
|
||||
it("fails for objects with different constructors", function() {
|
||||
var matchersUtil = new jasmineUnderTest.MatchersUtil();
|
||||
function One() {}
|
||||
function Two() {}
|
||||
|
||||
expect(jasmineUnderTest.matchersUtil.equals(new One(), new Two())).toBe(false);
|
||||
expect(matchersUtil.equals(new One(), new Two())).toBe(false);
|
||||
});
|
||||
|
||||
it("passes for Objects that are equivalent (simple case)", function() {
|
||||
expect(jasmineUnderTest.matchersUtil.equals({a: "foo"}, {a: "foo"})).toBe(true);
|
||||
var matchersUtil = new jasmineUnderTest.MatchersUtil();
|
||||
expect(matchersUtil.equals({a: "foo"}, {a: "foo"})).toBe(true);
|
||||
});
|
||||
|
||||
it("fails for Objects that are not equivalent (simple case)", function() {
|
||||
expect(jasmineUnderTest.matchersUtil.equals({a: "foo"}, {a: "bar"})).toBe(false);
|
||||
var matchersUtil = new jasmineUnderTest.MatchersUtil();
|
||||
expect(matchersUtil.equals({a: "foo"}, {a: "bar"})).toBe(false);
|
||||
});
|
||||
|
||||
it("passes for Objects that are equivalent (deep case)", function() {
|
||||
expect(jasmineUnderTest.matchersUtil.equals({a: "foo", b: { c: "bar"}}, {a: "foo", b: { c: "bar"}})).toBe(true);
|
||||
var matchersUtil = new jasmineUnderTest.MatchersUtil();
|
||||
expect(matchersUtil.equals({a: "foo", b: { c: "bar"}}, {a: "foo", b: { c: "bar"}})).toBe(true);
|
||||
});
|
||||
|
||||
it("fails for Objects that are not equivalent (deep case)", function() {
|
||||
expect(jasmineUnderTest.matchersUtil.equals({a: "foo", b: { c: "baz"}}, {a: "foo", b: { c: "bar"}})).toBe(false);
|
||||
var matchersUtil = new jasmineUnderTest.MatchersUtil();
|
||||
expect(matchersUtil.equals({a: "foo", b: { c: "baz"}}, {a: "foo", b: { c: "bar"}})).toBe(false);
|
||||
});
|
||||
|
||||
it("passes for Objects that are equivalent (with cycles)", function() {
|
||||
var actual = { a: "foo" },
|
||||
expected = { a: "foo" };
|
||||
expected = { a: "foo" },
|
||||
matchersUtil = new jasmineUnderTest.MatchersUtil();
|
||||
|
||||
actual.b = actual;
|
||||
expected.b = actual;
|
||||
|
||||
expect(jasmineUnderTest.matchersUtil.equals(actual, expected)).toBe(true);
|
||||
expect(matchersUtil.equals(actual, expected)).toBe(true);
|
||||
});
|
||||
|
||||
it("fails for Objects that are not equivalent (with cycles)", function() {
|
||||
var actual = { a: "foo" },
|
||||
expected = { a: "bar" };
|
||||
expected = { a: "bar" },
|
||||
matchersUtil = new jasmineUnderTest.MatchersUtil();
|
||||
|
||||
actual.b = actual;
|
||||
expected.b = actual;
|
||||
|
||||
expect(jasmineUnderTest.matchersUtil.equals(actual, expected)).toBe(false);
|
||||
expect(matchersUtil.equals(actual, expected)).toBe(false);
|
||||
});
|
||||
|
||||
it("fails for Objects that have the same number of keys, but different keys/values", function () {
|
||||
var expected = { a: undefined },
|
||||
actual = { b: 1 };
|
||||
actual = { b: 1 },
|
||||
matchersUtil = new jasmineUnderTest.MatchersUtil();
|
||||
|
||||
expect(jasmineUnderTest.matchersUtil.equals(actual, expected)).toBe(false);
|
||||
expect(matchersUtil.equals(actual, expected)).toBe(false);
|
||||
});
|
||||
|
||||
it("fails when comparing an empty object to an empty array (issue #114)", function() {
|
||||
var emptyObject = {},
|
||||
emptyArray = [];
|
||||
emptyArray = [],
|
||||
matchersUtil = new jasmineUnderTest.MatchersUtil();
|
||||
|
||||
expect(jasmineUnderTest.matchersUtil.equals(emptyObject, emptyArray)).toBe(false);
|
||||
expect(jasmineUnderTest.matchersUtil.equals(emptyArray, emptyObject)).toBe(false);
|
||||
|
||||
expect(matchersUtil.equals(emptyObject, emptyArray)).toBe(false);
|
||||
expect(matchersUtil.equals(emptyArray, emptyObject)).toBe(false);
|
||||
});
|
||||
|
||||
it("passes for equivalent frozen objects (GitHub issue #266)", function() {
|
||||
var a = { foo: 1 },
|
||||
b = {foo: 1 };
|
||||
b = {foo: 1 },
|
||||
matchersUtil = new jasmineUnderTest.MatchersUtil();
|
||||
|
||||
Object.freeze(a);
|
||||
Object.freeze(b);
|
||||
|
||||
expect(jasmineUnderTest.matchersUtil.equals(a,b)).toBe(true);
|
||||
expect(matchersUtil.equals(a,b)).toBe(true);
|
||||
});
|
||||
|
||||
it("passes for equivalent Promises (GitHub issue #1314)", function() {
|
||||
if (typeof Promise === 'undefined') { return; }
|
||||
|
||||
var p1 = new Promise(function () {}),
|
||||
p2 = new Promise(function () {});
|
||||
p2 = new Promise(function () {}),
|
||||
matchersUtil = new jasmineUnderTest.MatchersUtil();
|
||||
|
||||
expect(jasmineUnderTest.matchersUtil.equals(p1, p1)).toBe(true);
|
||||
expect(jasmineUnderTest.matchersUtil.equals(p1, p2)).toBe(false);
|
||||
expect(matchersUtil.equals(p1, p1)).toBe(true);
|
||||
expect(matchersUtil.equals(p1, p2)).toBe(false);
|
||||
});
|
||||
|
||||
describe("when running in a browser", function() {
|
||||
@@ -256,6 +295,8 @@ describe("matchersUtil", function() {
|
||||
return;
|
||||
}
|
||||
var a = document.createElement("div");
|
||||
var matchersUtil = new jasmineUnderTest.MatchersUtil();
|
||||
|
||||
a.setAttribute("test-attr", "attr-value");
|
||||
a.appendChild(document.createTextNode('test'));
|
||||
|
||||
@@ -263,17 +304,18 @@ describe("matchersUtil", function() {
|
||||
b.setAttribute("test-attr", "attr-value");
|
||||
b.appendChild(document.createTextNode('test'));
|
||||
|
||||
expect(jasmineUnderTest.matchersUtil.equals(a,b)).toBe(true);
|
||||
expect(matchersUtil.equals(a,b)).toBe(true);
|
||||
});
|
||||
|
||||
it("passes for equivalent objects from different frames", function() {
|
||||
if (isNotRunningInBrowser()) {
|
||||
return;
|
||||
}
|
||||
var matchersUtil = new jasmineUnderTest.MatchersUtil();
|
||||
var iframe = document.createElement('iframe');
|
||||
document.body.appendChild(iframe);
|
||||
iframe.contentWindow.eval('window.testObject = {}');
|
||||
expect(jasmineUnderTest.matchersUtil.equals({}, iframe.contentWindow.testObject)).toBe(true);
|
||||
expect(matchersUtil.equals({}, iframe.contentWindow.testObject)).toBe(true);
|
||||
document.body.removeChild(iframe);
|
||||
});
|
||||
|
||||
@@ -281,6 +323,7 @@ describe("matchersUtil", function() {
|
||||
if (isNotRunningInBrowser()) {
|
||||
return;
|
||||
}
|
||||
var matchersUtil = new jasmineUnderTest.MatchersUtil();
|
||||
var a = document.createElement("div");
|
||||
a.setAttribute("test-attr", "attr-value");
|
||||
a.appendChild(document.createTextNode('test'));
|
||||
@@ -289,16 +332,16 @@ describe("matchersUtil", function() {
|
||||
b.setAttribute("test-attr", "attr-value2");
|
||||
b.appendChild(document.createTextNode('test'));
|
||||
|
||||
expect(jasmineUnderTest.matchersUtil.equals(a,b)).toBe(false);
|
||||
expect(matchersUtil.equals(a,b)).toBe(false);
|
||||
|
||||
b.setAttribute("test-attr", "attr-value");
|
||||
expect(jasmineUnderTest.matchersUtil.equals(a,b)).toBe(true);
|
||||
expect(matchersUtil.equals(a,b)).toBe(true);
|
||||
|
||||
b.appendChild(document.createTextNode('2'));
|
||||
expect(jasmineUnderTest.matchersUtil.equals(a,b)).toBe(false);
|
||||
expect(matchersUtil.equals(a,b)).toBe(false);
|
||||
|
||||
a.appendChild(document.createTextNode('2'));
|
||||
expect(jasmineUnderTest.matchersUtil.equals(a,b)).toBe(true);
|
||||
expect(matchersUtil.equals(a,b)).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -311,43 +354,47 @@ describe("matchersUtil", function() {
|
||||
if (isNotRunningInNode()) {
|
||||
return;
|
||||
}
|
||||
var matchersUtil = new jasmineUnderTest.MatchersUtil();
|
||||
var vm = require('vm');
|
||||
var sandbox = {
|
||||
obj: null
|
||||
};
|
||||
vm.runInNewContext('obj = {a: 1, b: 2}', sandbox);
|
||||
|
||||
expect(jasmineUnderTest.matchersUtil.equals(sandbox.obj, {a: 1, b: 2})).toBe(true);
|
||||
expect(matchersUtil.equals(sandbox.obj, {a: 1, b: 2})).toBe(true);
|
||||
});
|
||||
|
||||
it("passes for equivalent arrays from different vm contexts", function() {
|
||||
if (isNotRunningInNode()) {
|
||||
return;
|
||||
}
|
||||
var matchersUtil = new jasmineUnderTest.MatchersUtil();
|
||||
var vm = require('vm');
|
||||
var sandbox = {
|
||||
arr: null
|
||||
};
|
||||
vm.runInNewContext('arr = [1, 2]', sandbox);
|
||||
|
||||
expect(jasmineUnderTest.matchersUtil.equals(sandbox.arr, [1, 2])).toBe(true);
|
||||
expect(matchersUtil.equals(sandbox.arr, [1, 2])).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
it("passes when Any is used", function() {
|
||||
var number = 3,
|
||||
anyNumber = new jasmineUnderTest.Any(Number);
|
||||
anyNumber = new jasmineUnderTest.Any(Number),
|
||||
matchersUtil = new jasmineUnderTest.MatchersUtil();
|
||||
|
||||
expect(jasmineUnderTest.matchersUtil.equals(number, anyNumber)).toBe(true);
|
||||
expect(jasmineUnderTest.matchersUtil.equals(anyNumber, number)).toBe(true);
|
||||
expect(matchersUtil.equals(number, anyNumber)).toBe(true);
|
||||
expect(matchersUtil.equals(anyNumber, number)).toBe(true);
|
||||
});
|
||||
|
||||
it("fails when Any is compared to something unexpected", function() {
|
||||
var number = 3,
|
||||
anyString = new jasmineUnderTest.Any(String);
|
||||
anyString = new jasmineUnderTest.Any(String),
|
||||
matchersUtil = new jasmineUnderTest.MatchersUtil();
|
||||
|
||||
expect(jasmineUnderTest.matchersUtil.equals(number, anyString)).toBe(false);
|
||||
expect(jasmineUnderTest.matchersUtil.equals(anyString, number)).toBe(false);
|
||||
expect(matchersUtil.equals(number, anyString)).toBe(false);
|
||||
expect(matchersUtil.equals(anyString, number)).toBe(false);
|
||||
});
|
||||
|
||||
it("passes when ObjectContaining is used", function() {
|
||||
@@ -355,135 +402,209 @@ describe("matchersUtil", function() {
|
||||
foo: 3,
|
||||
bar: 7
|
||||
},
|
||||
containing = new jasmineUnderTest.ObjectContaining({foo: 3});
|
||||
containing = new jasmineUnderTest.ObjectContaining({foo: 3}),
|
||||
matchersUtil = new jasmineUnderTest.MatchersUtil();
|
||||
|
||||
expect(jasmineUnderTest.matchersUtil.equals(obj, containing)).toBe(true);
|
||||
expect(jasmineUnderTest.matchersUtil.equals(containing, obj)).toBe(true);
|
||||
expect(matchersUtil.equals(obj, containing)).toBe(true);
|
||||
expect(matchersUtil.equals(containing, obj)).toBe(true);
|
||||
});
|
||||
|
||||
it("passes when MapContaining is used", function() {
|
||||
jasmine.getEnv().requireFunctioningMaps();
|
||||
|
||||
var matchersUtil = new jasmineUnderTest.MatchersUtil();
|
||||
var obj = new Map();
|
||||
obj.set(1, 2);
|
||||
obj.set('foo', 'bar');
|
||||
var containing = new jasmineUnderTest.MapContaining(new Map());
|
||||
containing.sample.set('foo', 'bar');
|
||||
|
||||
expect(jasmineUnderTest.matchersUtil.equals(obj, containing)).toBe(true);
|
||||
expect(jasmineUnderTest.matchersUtil.equals(containing, obj)).toBe(true);
|
||||
expect(matchersUtil.equals(obj, containing)).toBe(true);
|
||||
expect(matchersUtil.equals(containing, obj)).toBe(true);
|
||||
});
|
||||
|
||||
it("passes when SetContaining is used", function() {
|
||||
jasmine.getEnv().requireFunctioningSets();
|
||||
|
||||
var matchersUtil = new jasmineUnderTest.MatchersUtil();
|
||||
var obj = new Set();
|
||||
obj.add(1);
|
||||
obj.add('foo');
|
||||
var containing = new jasmineUnderTest.SetContaining(new Set());
|
||||
containing.sample.add(1);
|
||||
|
||||
expect(jasmineUnderTest.matchersUtil.equals(obj, containing)).toBe(true);
|
||||
expect(jasmineUnderTest.matchersUtil.equals(containing, obj)).toBe(true);
|
||||
expect(matchersUtil.equals(obj, containing)).toBe(true);
|
||||
expect(matchersUtil.equals(containing, obj)).toBe(true);
|
||||
});
|
||||
|
||||
it("passes when an asymmetric equality tester returns true", function() {
|
||||
var tester = { asymmetricMatch: function(other) { return true; } };
|
||||
var tester = { asymmetricMatch: function(other) { return true; } },
|
||||
matchersUtil = new jasmineUnderTest.MatchersUtil();
|
||||
|
||||
expect(jasmineUnderTest.matchersUtil.equals(false, tester)).toBe(true);
|
||||
expect(jasmineUnderTest.matchersUtil.equals(tester, false)).toBe(true);
|
||||
expect(matchersUtil.equals(false, tester)).toBe(true);
|
||||
expect(matchersUtil.equals(tester, false)).toBe(true);
|
||||
});
|
||||
|
||||
it("fails when an asymmetric equality tester returns false", function() {
|
||||
var tester = { asymmetricMatch: function(other) { return false; } };
|
||||
var tester = { asymmetricMatch: function(other) { return false; } },
|
||||
matchersUtil = new jasmineUnderTest.MatchersUtil();
|
||||
|
||||
expect(jasmineUnderTest.matchersUtil.equals(true, tester)).toBe(false);
|
||||
expect(jasmineUnderTest.matchersUtil.equals(tester, true)).toBe(false);
|
||||
expect(matchersUtil.equals(true, tester)).toBe(false);
|
||||
expect(matchersUtil.equals(tester, true)).toBe(false);
|
||||
});
|
||||
|
||||
it("passes when ArrayContaining is used", function() {
|
||||
var arr = ["foo", "bar"];
|
||||
var arr = ["foo", "bar"],
|
||||
matchersUtil = new jasmineUnderTest.MatchersUtil();
|
||||
|
||||
expect(jasmineUnderTest.matchersUtil.equals(arr, new jasmineUnderTest.ArrayContaining(["bar"]))).toBe(true);
|
||||
expect(matchersUtil.equals(arr, new jasmineUnderTest.ArrayContaining(["bar"]))).toBe(true);
|
||||
});
|
||||
|
||||
it("passes when a custom equality matcher returns true", function() {
|
||||
var tester = function(a, b) { return true; };
|
||||
it("passes when a custom equality matcher passed to equals returns true", function() {
|
||||
// TODO: remove this in the next major release.
|
||||
var tester = function(a, b) { return true; },
|
||||
matchersUtil = new jasmineUnderTest.MatchersUtil();
|
||||
|
||||
expect(jasmineUnderTest.matchersUtil.equals(1, 2, [tester])).toBe(true);
|
||||
expect(matchersUtil.equals(1, 2, [tester])).toBe(true);
|
||||
});
|
||||
|
||||
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], pp: function() {}});
|
||||
|
||||
expect(matchersUtil.equals(1, 2)).toBe(true);
|
||||
});
|
||||
|
||||
it("passes for two empty Objects", function () {
|
||||
expect(jasmineUnderTest.matchersUtil.equals({}, {})).toBe(true);
|
||||
var matchersUtil = new jasmineUnderTest.MatchersUtil();
|
||||
expect(matchersUtil.equals({}, {})).toBe(true);
|
||||
});
|
||||
|
||||
describe("when a custom equality matcher is installed that returns 'undefined'", function () {
|
||||
describe("when a custom equality matcher is passed to equals that returns 'undefined'", function () {
|
||||
// TODO: remove this in the next major release.
|
||||
var tester = function(a, b) { return jasmine.undefined; };
|
||||
|
||||
it("passes for two empty Objects", function () {
|
||||
expect(jasmineUnderTest.matchersUtil.equals({}, {}, [tester])).toBe(true);
|
||||
var matchersUtil = new jasmineUnderTest.MatchersUtil();
|
||||
expect(matchersUtil.equals({}, {}, [tester])).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
it("fails for equivalents when a custom equality matcher returns false", function() {
|
||||
var tester = function(a, b) { return false; };
|
||||
describe("when a custom equality matcher is passed to the constructor that returns 'undefined'", function () {
|
||||
var tester = function(a, b) { return jasmine.undefined; };
|
||||
|
||||
expect(jasmineUnderTest.matchersUtil.equals(1, 1, [tester])).toBe(false);
|
||||
it("passes for two empty Objects", function () {
|
||||
var matchersUtil = new jasmineUnderTest.MatchersUtil({customTesters: [tester], pp: function() {}});
|
||||
expect(matchersUtil.equals({}, {})).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
it("passes for an asymmetric equality tester that returns true when a custom equality tester return false", function() {
|
||||
it("fails for equivalents when a custom equality matcher passed to equals returns false", function() {
|
||||
// TODO: remove this in the next major release.
|
||||
var tester = function(a, b) { return false; },
|
||||
matchersUtil = new jasmineUnderTest.MatchersUtil();
|
||||
|
||||
expect(matchersUtil.equals(1, 1, [tester])).toBe(false);
|
||||
});
|
||||
|
||||
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], pp: function() {}});
|
||||
|
||||
expect(matchersUtil.equals(1, 1)).toBe(false);
|
||||
});
|
||||
|
||||
it("passes for an asymmetric equality tester that returns true when a custom equality tester passed to equals return false", function() {
|
||||
// TODO: remove this in the next major release.
|
||||
var asymmetricTester = { asymmetricMatch: function(other) { return true; } },
|
||||
symmetricTester = function(a, b) { return false; };
|
||||
symmetricTester = function(a, b) { return false; },
|
||||
matchersUtil = new jasmineUnderTest.MatchersUtil();
|
||||
|
||||
expect(jasmineUnderTest.matchersUtil.equals(asymmetricTester, true, [symmetricTester])).toBe(true);
|
||||
expect(jasmineUnderTest.matchersUtil.equals(true, asymmetricTester, [symmetricTester])).toBe(true);
|
||||
expect(matchersUtil.equals(asymmetricTester, true, [symmetricTester])).toBe(true);
|
||||
expect(matchersUtil.equals(true, asymmetricTester, [symmetricTester])).toBe(true);
|
||||
});
|
||||
|
||||
it("passes custom equality matchers to asymmetric equality testers", function() {
|
||||
var tester = function(a, b) {};
|
||||
var asymmetricTester = { asymmetricMatch: jasmine.createSpy('asymmetricMatch') };
|
||||
asymmetricTester.asymmetricMatch.and.returnValue(true);
|
||||
var other = {};
|
||||
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()], pp: function() {}});
|
||||
|
||||
expect(jasmineUnderTest.matchersUtil.equals(asymmetricTester, other, [tester])).toBe(true);
|
||||
expect(asymmetricTester.asymmetricMatch).toHaveBeenCalledWith(other, [tester]);
|
||||
expect(matchersUtil.equals(asymmetricTester, true)).toBe(true);
|
||||
expect(matchersUtil.equals(true, asymmetricTester)).toBe(true);
|
||||
});
|
||||
|
||||
describe("The compatibility shim passed to asymmetric equality testers", function() {
|
||||
describe("When equals is called with custom equality testers", function() {
|
||||
it("is both a matchersUtil and the custom equality testers passed to equals", function() {
|
||||
var asymmetricTester = jasmine.createSpyObj('tester', ['asymmetricMatch']),
|
||||
symmetricTester = function() { } ,
|
||||
matchersUtil = new jasmineUnderTest.MatchersUtil(),
|
||||
shim;
|
||||
|
||||
matchersUtil.equals(true, asymmetricTester, [symmetricTester]);
|
||||
shim = asymmetricTester.asymmetricMatch.calls.argsFor(0)[1];
|
||||
expect(shim).toEqual(jasmine.any(jasmineUnderTest.MatchersUtil));
|
||||
expect(shim.length).toEqual(1);
|
||||
expect(shim[0]).toEqual(symmetricTester);
|
||||
});
|
||||
});
|
||||
|
||||
describe("When equals is called with custom equality testers", 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], pp: function() {}}),
|
||||
shim;
|
||||
|
||||
matchersUtil.equals(true, asymmetricTester);
|
||||
shim = asymmetricTester.asymmetricMatch.calls.argsFor(0)[1];
|
||||
expect(shim).toEqual(jasmine.any(jasmineUnderTest.MatchersUtil));
|
||||
expect(shim.length).toEqual(1);
|
||||
expect(shim[0]).toEqual(symmetricTester);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
it("passes when an Any is compared to an Any that checks for the same type", function() {
|
||||
var any1 = new jasmineUnderTest.Any(Function),
|
||||
any2 = new jasmineUnderTest.Any(Function);
|
||||
any2 = new jasmineUnderTest.Any(Function),
|
||||
matchersUtil = new jasmineUnderTest.MatchersUtil();
|
||||
|
||||
expect(jasmineUnderTest.matchersUtil.equals(any1, any2)).toBe(true);
|
||||
expect(matchersUtil.equals(any1, any2)).toBe(true);
|
||||
});
|
||||
|
||||
it("passes for null prototype objects with same properties", function () {
|
||||
var objA = Object.create(null),
|
||||
objB = Object.create(null);
|
||||
objB = Object.create(null),
|
||||
matchersUtil = new jasmineUnderTest.MatchersUtil();
|
||||
|
||||
objA.name = 'test';
|
||||
objB.name = 'test';
|
||||
|
||||
expect(jasmineUnderTest.matchersUtil.equals(objA, objB)).toBe(true);
|
||||
expect(matchersUtil.equals(objA, objB)).toBe(true);
|
||||
});
|
||||
|
||||
it("fails for null prototype objects with different properties", function () {
|
||||
var objA = Object.create(null),
|
||||
objB = Object.create(null);
|
||||
objB = Object.create(null),
|
||||
matchersUtil = new jasmineUnderTest.MatchersUtil();
|
||||
|
||||
objA.name = 'test';
|
||||
objB.test = 'name';
|
||||
|
||||
expect(jasmineUnderTest.matchersUtil.equals(objA, objB)).toBe(false);
|
||||
expect(matchersUtil.equals(objA, objB)).toBe(false);
|
||||
});
|
||||
|
||||
it("passes when comparing two empty sets", function() {
|
||||
jasmine.getEnv().requireFunctioningSets();
|
||||
expect(jasmineUnderTest.matchersUtil.equals(new Set(), new Set())).toBe(true);
|
||||
var matchersUtil = new jasmineUnderTest.MatchersUtil();
|
||||
expect(matchersUtil.equals(new Set(), new Set())).toBe(true);
|
||||
});
|
||||
|
||||
it("passes when comparing identical sets", function() {
|
||||
jasmine.getEnv().requireFunctioningSets();
|
||||
|
||||
var matchersUtil = new jasmineUnderTest.MatchersUtil();
|
||||
var setA = new Set();
|
||||
setA.add(6);
|
||||
setA.add(5);
|
||||
@@ -491,12 +612,13 @@ describe("matchersUtil", function() {
|
||||
setB.add(6);
|
||||
setB.add(5);
|
||||
|
||||
expect(jasmineUnderTest.matchersUtil.equals(setA, setB)).toBe(true);
|
||||
expect(matchersUtil.equals(setA, setB)).toBe(true);
|
||||
});
|
||||
|
||||
it("passes when comparing identical sets with different insertion order and simple elements", function() {
|
||||
jasmine.getEnv().requireFunctioningSets();
|
||||
|
||||
var matchersUtil = new jasmineUnderTest.MatchersUtil();
|
||||
var setA = new Set();
|
||||
setA.add(3);
|
||||
setA.add(6);
|
||||
@@ -504,12 +626,13 @@ describe("matchersUtil", function() {
|
||||
setB.add(6);
|
||||
setB.add(3);
|
||||
|
||||
expect(jasmineUnderTest.matchersUtil.equals(setA, setB)).toBe(true);
|
||||
expect(matchersUtil.equals(setA, setB)).toBe(true);
|
||||
});
|
||||
|
||||
it("passes when comparing identical sets with different insertion order and complex elements 1", function() {
|
||||
jasmine.getEnv().requireFunctioningSets();
|
||||
|
||||
var matchersUtil = new jasmineUnderTest.MatchersUtil();
|
||||
var setA1 = new Set();
|
||||
setA1.add(['a',3]);
|
||||
setA1.add([6,1]);
|
||||
@@ -531,12 +654,13 @@ describe("matchersUtil", function() {
|
||||
setB.add(setB1);
|
||||
setB.add(setB2);
|
||||
|
||||
expect(jasmineUnderTest.matchersUtil.equals(setA, setB)).toBe(true);
|
||||
expect(matchersUtil.equals(setA, setB)).toBe(true);
|
||||
});
|
||||
|
||||
it("passes when comparing identical sets with different insertion order and complex elements 2", function() {
|
||||
jasmine.getEnv().requireFunctioningSets();
|
||||
|
||||
var matchersUtil = new jasmineUnderTest.MatchersUtil();
|
||||
var setA = new Set();
|
||||
setA.add([[1,2], [3,4]]);
|
||||
setA.add([[5,6], [7,8]]);
|
||||
@@ -544,11 +668,12 @@ describe("matchersUtil", function() {
|
||||
setB.add([[5,6], [7,8]]);
|
||||
setB.add([[1,2], [3,4]]);
|
||||
|
||||
expect(jasmineUnderTest.matchersUtil.equals(setA, setB)).toBe(true);
|
||||
expect(matchersUtil.equals(setA, setB)).toBe(true);
|
||||
});
|
||||
|
||||
it("fails for sets with different elements", function() {
|
||||
jasmine.getEnv().requireFunctioningSets();
|
||||
var matchersUtil = new jasmineUnderTest.MatchersUtil();
|
||||
var setA = new Set();
|
||||
setA.add(6);
|
||||
setA.add(3);
|
||||
@@ -558,11 +683,12 @@ describe("matchersUtil", function() {
|
||||
setB.add(4);
|
||||
setB.add(5);
|
||||
|
||||
expect(jasmineUnderTest.matchersUtil.equals(setA, setB)).toBe(false);
|
||||
expect(matchersUtil.equals(setA, setB)).toBe(false);
|
||||
});
|
||||
|
||||
it("fails for sets of different size", function() {
|
||||
jasmine.getEnv().requireFunctioningSets();
|
||||
var matchersUtil = new jasmineUnderTest.MatchersUtil();
|
||||
var setA = new Set();
|
||||
setA.add(6);
|
||||
setA.add(3);
|
||||
@@ -571,36 +697,40 @@ describe("matchersUtil", function() {
|
||||
setB.add(4);
|
||||
setB.add(5);
|
||||
|
||||
expect(jasmineUnderTest.matchersUtil.equals(setA, setB)).toBe(false);
|
||||
expect(matchersUtil.equals(setA, setB)).toBe(false);
|
||||
});
|
||||
|
||||
it("passes when comparing two empty maps", function() {
|
||||
jasmine.getEnv().requireFunctioningMaps();
|
||||
expect(jasmineUnderTest.matchersUtil.equals(new Map(), new Map())).toBe(true);
|
||||
var matchersUtil = new jasmineUnderTest.MatchersUtil();
|
||||
expect(matchersUtil.equals(new Map(), new Map())).toBe(true);
|
||||
});
|
||||
|
||||
it("passes when comparing identical maps", function() {
|
||||
jasmine.getEnv().requireFunctioningMaps();
|
||||
var matchersUtil = new jasmineUnderTest.MatchersUtil();
|
||||
var mapA = new Map();
|
||||
mapA.set(6, 5);
|
||||
var mapB = new Map();
|
||||
mapB.set(6, 5);
|
||||
expect(jasmineUnderTest.matchersUtil.equals(mapA, mapB)).toBe(true);
|
||||
expect(matchersUtil.equals(mapA, mapB)).toBe(true);
|
||||
});
|
||||
|
||||
it("passes when comparing identical maps with different insertion order", function() {
|
||||
jasmine.getEnv().requireFunctioningMaps();
|
||||
var matchersUtil = new jasmineUnderTest.MatchersUtil();
|
||||
var mapA = new Map();
|
||||
mapA.set("a", 3);
|
||||
mapA.set(6, 1);
|
||||
var mapB = new Map();
|
||||
mapB.set(6, 1);
|
||||
mapB.set("a", 3);
|
||||
expect(jasmineUnderTest.matchersUtil.equals(mapA, mapB)).toBe(true);
|
||||
expect(matchersUtil.equals(mapA, mapB)).toBe(true);
|
||||
});
|
||||
|
||||
it("fails for maps with different elements", function() {
|
||||
jasmine.getEnv().requireFunctioningMaps();
|
||||
var matchersUtil = new jasmineUnderTest.MatchersUtil();
|
||||
var mapA = new Map();
|
||||
mapA.set(6, 3);
|
||||
mapA.set(5, 1);
|
||||
@@ -608,17 +738,18 @@ describe("matchersUtil", function() {
|
||||
mapB.set(6, 4);
|
||||
mapB.set(5, 1);
|
||||
|
||||
expect(jasmineUnderTest.matchersUtil.equals(mapA, mapB)).toBe(false);
|
||||
expect(matchersUtil.equals(mapA, mapB)).toBe(false);
|
||||
});
|
||||
|
||||
it("fails for maps of different size", function() {
|
||||
jasmine.getEnv().requireFunctioningMaps();
|
||||
var matchersUtil = new jasmineUnderTest.MatchersUtil();
|
||||
var mapA = new Map();
|
||||
mapA.set(6, 3);
|
||||
var mapB = new Map();
|
||||
mapB.set(6, 4);
|
||||
mapB.set(5, 1);
|
||||
expect(jasmineUnderTest.matchersUtil.equals(mapA, mapB)).toBe(false);
|
||||
expect(matchersUtil.equals(mapA, mapB)).toBe(false);
|
||||
});
|
||||
|
||||
describe("when running in an environment with array polyfills", function() {
|
||||
@@ -673,105 +804,160 @@ describe("matchersUtil", function() {
|
||||
return {
|
||||
self: 'asymmetric tester value',
|
||||
other: 'other value'
|
||||
}
|
||||
};
|
||||
}
|
||||
},
|
||||
diffBuilder = jasmine.createSpyObj('diffBuilder', ['record', 'withPath']);
|
||||
diffBuilder.withPath.and.callFake(function(p, block) { block() });
|
||||
jasmineUnderTest.matchersUtil.equals({x: 42}, {x: tester}, [], diffBuilder);
|
||||
actual = {x: 42},
|
||||
expected = {x: tester},
|
||||
diffBuilder = jasmine.createSpyObj('diffBuilder', ['recordMismatch', 'withPath', 'setRoots']);
|
||||
|
||||
diffBuilder.withPath.and.callFake(function(p, block) { block(); });
|
||||
jasmineUnderTest.matchersUtil.equals(actual, expected, [], diffBuilder);
|
||||
|
||||
expect(diffBuilder.setRoots).toHaveBeenCalledWith(actual, expected);
|
||||
expect(diffBuilder.withPath).toHaveBeenCalledWith('x', jasmine.any(Function));
|
||||
expect(diffBuilder.record). toHaveBeenCalledWith(
|
||||
'other value', 'asymmetric tester value'
|
||||
);
|
||||
expect(diffBuilder.recordMismatch). toHaveBeenCalledWith();
|
||||
});
|
||||
|
||||
it("records both objects when the tester does not implement valuesForDiff", function() {
|
||||
var tester = {
|
||||
asymmetricMatch: function() { return false; },
|
||||
},
|
||||
diffBuilder = jasmine.createSpyObj('diffBuilder', ['record', 'withPath']);
|
||||
diffBuilder.withPath.and.callFake(function(p, block) { block() });
|
||||
jasmineUnderTest.matchersUtil.equals({x: 42}, {x: tester}, [], diffBuilder);
|
||||
actual = {x: 42},
|
||||
expected = {x: tester},
|
||||
diffBuilder = jasmine.createSpyObj('diffBuilder', ['recordMismatch', 'withPath', 'setRoots']);
|
||||
diffBuilder.withPath.and.callFake(function(p, block) { block(); });
|
||||
jasmineUnderTest.matchersUtil.equals(actual, expected, [], diffBuilder);
|
||||
|
||||
expect(diffBuilder.setRoots).toHaveBeenCalledWith(actual, expected);
|
||||
expect(diffBuilder.withPath).toHaveBeenCalledWith('x', jasmine.any(Function));
|
||||
expect(diffBuilder.record). toHaveBeenCalledWith(42, tester);
|
||||
expect(diffBuilder.recordMismatch). toHaveBeenCalledWith();
|
||||
});
|
||||
});
|
||||
|
||||
it('uses a diffBuilder if one is provided as the fourth argument', function() {
|
||||
// TODO: remove this in the next major release.
|
||||
var diffBuilder = new jasmineUnderTest.DiffBuilder(),
|
||||
matchersUtil = new jasmineUnderTest.MatchersUtil();
|
||||
|
||||
spyOn(diffBuilder, 'recordMismatch');
|
||||
spyOn(diffBuilder, 'withPath').and.callThrough();
|
||||
|
||||
matchersUtil.equals([1], [2], [], diffBuilder);
|
||||
expect(diffBuilder.withPath).toHaveBeenCalledWith('length', jasmine.any(Function));
|
||||
expect(diffBuilder.withPath).toHaveBeenCalledWith(0, jasmine.any(Function));
|
||||
expect(diffBuilder.recordMismatch).toHaveBeenCalledWith();
|
||||
});
|
||||
|
||||
it('uses a diffBuilder if one is provided as the third argument', function() {
|
||||
var diffBuilder = new jasmineUnderTest.DiffBuilder(),
|
||||
matchersUtil = new jasmineUnderTest.MatchersUtil();
|
||||
|
||||
spyOn(diffBuilder, 'recordMismatch');
|
||||
spyOn(diffBuilder, 'withPath').and.callThrough();
|
||||
|
||||
matchersUtil.equals([1], [2], diffBuilder);
|
||||
expect(diffBuilder.withPath).toHaveBeenCalledWith('length', jasmine.any(Function));
|
||||
expect(diffBuilder.withPath).toHaveBeenCalledWith(0, jasmine.any(Function));
|
||||
expect(diffBuilder.recordMismatch).toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
|
||||
describe("contains", function() {
|
||||
it("passes when expected is a substring of actual", function() {
|
||||
expect(jasmineUnderTest.matchersUtil.contains("ABC", "BC")).toBe(true);
|
||||
var matchersUtil = new jasmineUnderTest.MatchersUtil();
|
||||
expect(matchersUtil.contains("ABC", "BC")).toBe(true);
|
||||
});
|
||||
|
||||
it("fails when expected is a not substring of actual", function() {
|
||||
expect(jasmineUnderTest.matchersUtil.contains("ABC", "X")).toBe(false);
|
||||
var matchersUtil = new jasmineUnderTest.MatchersUtil();
|
||||
expect(matchersUtil.contains("ABC", "X")).toBe(false);
|
||||
});
|
||||
|
||||
it("passes when expected is an element in an actual array", function() {
|
||||
expect(jasmineUnderTest.matchersUtil.contains(['foo', 'bar'], 'foo')).toBe(true);
|
||||
var matchersUtil = new jasmineUnderTest.MatchersUtil();
|
||||
expect(matchersUtil.contains(['foo', 'bar'], 'foo')).toBe(true);
|
||||
});
|
||||
|
||||
it("fails when expected is not an element in an actual array", function() {
|
||||
expect(jasmineUnderTest.matchersUtil.contains(['foo', 'bar'], 'baz')).toBe(false);
|
||||
var matchersUtil = new jasmineUnderTest.MatchersUtil();
|
||||
expect(matchersUtil.contains(['foo', 'bar'], 'baz')).toBe(false);
|
||||
});
|
||||
|
||||
it("passes with mixed-element arrays", function() {
|
||||
expect(jasmineUnderTest.matchersUtil.contains(["foo", {some: "bar"}], "foo")).toBe(true);
|
||||
expect(jasmineUnderTest.matchersUtil.contains(["foo", {some: "bar"}], {some: "bar"})).toBe(true);
|
||||
var matchersUtil = new jasmineUnderTest.MatchersUtil();
|
||||
expect(matchersUtil.contains(["foo", {some: "bar"}], "foo")).toBe(true);
|
||||
expect(matchersUtil.contains(["foo", {some: "bar"}], {some: "bar"})).toBe(true);
|
||||
});
|
||||
|
||||
it("uses custom equality testers if passed in and actual is an Array", function() {
|
||||
var customTester = function(a, b) {return true;};
|
||||
it("uses custom equality testers if passed to contains and actual is an Array", function() {
|
||||
// TODO: remove this in the next major release.
|
||||
var customTester = function(a, b) {return true;},
|
||||
matchersUtil = new jasmineUnderTest.MatchersUtil();
|
||||
|
||||
expect(jasmineUnderTest.matchersUtil.contains([1, 2], 3, [customTester])).toBe(true);
|
||||
expect(matchersUtil.contains([1, 2], 3, [customTester])).toBe(true);
|
||||
});
|
||||
|
||||
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], pp: function() {}});
|
||||
|
||||
expect(matchersUtil.contains([1, 2], 3)).toBe(true);
|
||||
});
|
||||
|
||||
it("fails when actual is undefined", function() {
|
||||
expect(jasmineUnderTest.matchersUtil.contains(undefined, 'A')).toBe(false);
|
||||
var matchersUtil = new jasmineUnderTest.MatchersUtil();
|
||||
expect(matchersUtil.contains(undefined, 'A')).toBe(false);
|
||||
});
|
||||
|
||||
it("fails when actual is null", function() {
|
||||
expect(jasmineUnderTest.matchersUtil.contains(null, 'A')).toBe(false);
|
||||
var matchersUtil = new jasmineUnderTest.MatchersUtil();
|
||||
expect(matchersUtil.contains(null, 'A')).toBe(false);
|
||||
});
|
||||
|
||||
it("passes with array-like objects", function() {
|
||||
var capturedArgs = null;
|
||||
var capturedArgs = null,
|
||||
matchersUtil = new jasmineUnderTest.MatchersUtil();
|
||||
|
||||
function testFunction(){
|
||||
capturedArgs = arguments;
|
||||
}
|
||||
|
||||
testFunction('foo', 'bar');
|
||||
expect(jasmineUnderTest.matchersUtil.contains(capturedArgs, 'bar')).toBe(true);
|
||||
expect(matchersUtil.contains(capturedArgs, 'bar')).toBe(true);
|
||||
});
|
||||
|
||||
it("passes for set members", function() {
|
||||
jasmine.getEnv().requireFunctioningSets();
|
||||
|
||||
var matchersUtil = new jasmineUnderTest.MatchersUtil();
|
||||
var setItem = {'foo': 'bar'};
|
||||
var set = new Set();
|
||||
set.add(setItem);
|
||||
|
||||
expect(jasmineUnderTest.matchersUtil.contains(set, setItem)).toBe(true);
|
||||
expect(matchersUtil.contains(set, setItem)).toBe(true);
|
||||
});
|
||||
|
||||
// documenting current behavior
|
||||
it("fails (!) for objects that equal to a set member", function() {
|
||||
jasmine.getEnv().requireFunctioningSets();
|
||||
|
||||
var matchersUtil = new jasmineUnderTest.MatchersUtil();
|
||||
var set = new Set();
|
||||
set.add({'foo': 'bar'});
|
||||
|
||||
expect(jasmineUnderTest.matchersUtil.contains(set, {'foo': 'bar'})).toBe(false);
|
||||
expect(matchersUtil.contains(set, {'foo': 'bar'})).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
describe("buildMessage", function() {
|
||||
describe("buildFailureMessage", function() {
|
||||
|
||||
it("builds an English sentence for a failure case", function() {
|
||||
var actual = "foo",
|
||||
name = "toBar",
|
||||
message = jasmineUnderTest.matchersUtil.buildFailureMessage(name, false, actual);
|
||||
pp = jasmineUnderTest.makePrettyPrinter(),
|
||||
matchersUtil = new jasmineUnderTest.MatchersUtil({pp: pp}),
|
||||
message = matchersUtil.buildFailureMessage(name, false, actual);
|
||||
|
||||
expect(message).toEqual("Expected 'foo' to bar.");
|
||||
});
|
||||
@@ -780,7 +966,9 @@ describe("matchersUtil", function() {
|
||||
var actual = "foo",
|
||||
name = "toBar",
|
||||
isNot = true,
|
||||
message = message = jasmineUnderTest.matchersUtil.buildFailureMessage(name, isNot, actual);
|
||||
pp = jasmineUnderTest.makePrettyPrinter(),
|
||||
matchersUtil = new jasmineUnderTest.MatchersUtil({pp: pp}),
|
||||
message = message = matchersUtil.buildFailureMessage(name, isNot, actual);
|
||||
|
||||
expect(message).toEqual("Expected 'foo' not to bar.");
|
||||
});
|
||||
@@ -788,9 +976,24 @@ describe("matchersUtil", function() {
|
||||
it("builds an English sentence for an arbitrary array of expected arguments", function() {
|
||||
var actual = "foo",
|
||||
name = "toBar",
|
||||
message = jasmineUnderTest.matchersUtil.buildFailureMessage(name, false, actual, "quux", "corge");
|
||||
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 expecteds and actual", function() {
|
||||
var actual = "foo",
|
||||
expected1 = "qux",
|
||||
expected2 = "grault",
|
||||
name = "toBar",
|
||||
isNot = false,
|
||||
pp = function(value) { return '<' + value + '>'; },
|
||||
matchersUtil = new jasmineUnderTest.MatchersUtil({pp: pp}),
|
||||
message = message = matchersUtil.buildFailureMessage(name, isNot, actual, expected1, expected2);
|
||||
|
||||
expect(message).toEqual("Expected <foo> to bar <qux>, <grault>.");
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -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' +
|
||||
|
||||
@@ -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.")
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
describe("toBe", function() {
|
||||
it("passes with no message when actual === expected", function() {
|
||||
var matcher = jasmineUnderTest.matchers.toBe(jasmineUnderTest.matchersUtil),
|
||||
var matchersUtil = new jasmineUnderTest.MatchersUtil(),
|
||||
matcher = jasmineUnderTest.matchers.toBe(matchersUtil),
|
||||
result;
|
||||
|
||||
result = matcher.compare(1, 1);
|
||||
@@ -8,7 +9,8 @@ describe("toBe", function() {
|
||||
});
|
||||
|
||||
it("passes with a custom message when expected is an array", function() {
|
||||
var matcher = jasmineUnderTest.matchers.toBe(jasmineUnderTest.matchersUtil),
|
||||
var matchersUtil = new jasmineUnderTest.MatchersUtil({pp: jasmineUnderTest.makePrettyPrinter()}),
|
||||
matcher = jasmineUnderTest.matchers.toBe(matchersUtil),
|
||||
result,
|
||||
array = [1];
|
||||
|
||||
@@ -18,7 +20,8 @@ describe("toBe", function() {
|
||||
});
|
||||
|
||||
it("passes with a custom message when expected is an object", function() {
|
||||
var matcher = jasmineUnderTest.matchers.toBe(jasmineUnderTest.matchersUtil),
|
||||
var matchersUtil = new jasmineUnderTest.MatchersUtil({pp: jasmineUnderTest.makePrettyPrinter()}),
|
||||
matcher = jasmineUnderTest.matchers.toBe(matchersUtil),
|
||||
result,
|
||||
obj = {foo: "bar"};
|
||||
|
||||
@@ -28,7 +31,8 @@ describe("toBe", function() {
|
||||
});
|
||||
|
||||
it("fails with no message when actual !== expected", function() {
|
||||
var matcher = jasmineUnderTest.matchers.toBe(jasmineUnderTest.matchersUtil),
|
||||
var matchersUtil = new jasmineUnderTest.MatchersUtil(),
|
||||
matcher = jasmineUnderTest.matchers.toBe(matchersUtil),
|
||||
result;
|
||||
|
||||
result = matcher.compare(1, 2);
|
||||
@@ -37,7 +41,8 @@ describe("toBe", function() {
|
||||
});
|
||||
|
||||
it("fails with a custom message when expected is an array", function() {
|
||||
var matcher = jasmineUnderTest.matchers.toBe(jasmineUnderTest.matchersUtil),
|
||||
var matchersUtil = new jasmineUnderTest.MatchersUtil({pp: jasmineUnderTest.makePrettyPrinter()}),
|
||||
matcher = jasmineUnderTest.matchers.toBe(matchersUtil),
|
||||
result;
|
||||
|
||||
result = matcher.compare([1], [1]);
|
||||
@@ -46,11 +51,24 @@ describe("toBe", function() {
|
||||
});
|
||||
|
||||
it("fails with a custom message when expected is an object", function() {
|
||||
var matcher = jasmineUnderTest.matchers.toBe(jasmineUnderTest.matchersUtil),
|
||||
var matchersUtil = new jasmineUnderTest.MatchersUtil({pp: jasmineUnderTest.makePrettyPrinter()}),
|
||||
matcher = jasmineUnderTest.matchers.toBe(matchersUtil),
|
||||
result;
|
||||
|
||||
result = matcher.compare({foo: "bar"}, {foo: "bar"});
|
||||
expect(result.pass).toBe(false);
|
||||
expect(result.message).toBe("Expected Object({ foo: 'bar' }) to be Object({ foo: 'bar' }). Tip: To check for deep equality, use .toEqual() instead of .toBe().")
|
||||
});
|
||||
|
||||
it("works with custom object formatters when expected is an object", function() {
|
||||
var formatter = function(x) { return '<' + x.foo + '>'; },
|
||||
prettyPrinter = jasmineUnderTest.makePrettyPrinter([formatter]),
|
||||
matchersUtil = new jasmineUnderTest.MatchersUtil({pp: prettyPrinter}),
|
||||
matcher = jasmineUnderTest.matchers.toBe(matchersUtil),
|
||||
result;
|
||||
|
||||
result = matcher.compare({foo: "bar"}, {foo: "bar"});
|
||||
expect(result.pass).toBe(false);
|
||||
expect(result.message).toBe("Expected <bar> to be <bar>. Tip: To check for deep equality, use .toEqual() instead of .toBe().")
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,26 +1,25 @@
|
||||
describe("toContain", function() {
|
||||
it("delegates to jasmineUnderTest.matchersUtil.contains", function() {
|
||||
var util = {
|
||||
var matchersUtil = {
|
||||
contains: jasmine.createSpy('delegated-contains').and.returnValue(true)
|
||||
},
|
||||
matcher = jasmineUnderTest.matchers.toContain(util),
|
||||
matcher = jasmineUnderTest.matchers.toContain(matchersUtil),
|
||||
result;
|
||||
|
||||
result = matcher.compare("ABC", "B");
|
||||
expect(util.contains).toHaveBeenCalledWith("ABC", "B", []);
|
||||
expect(matchersUtil.contains).toHaveBeenCalledWith("ABC", "B");
|
||||
expect(result.pass).toBe(true);
|
||||
});
|
||||
|
||||
it("delegates to jasmineUnderTest.matchersUtil.contains, passing in equality testers if present", function() {
|
||||
var util = {
|
||||
contains: jasmine.createSpy('delegated-contains').and.returnValue(true)
|
||||
it("works with custom equality testers", function() {
|
||||
var tester = function (a, b) {
|
||||
return a.toString() === b.toString();
|
||||
},
|
||||
customEqualityTesters = ['a', 'b'],
|
||||
matcher = jasmineUnderTest.matchers.toContain(util, customEqualityTesters),
|
||||
matchersUtil = new jasmineUnderTest.MatchersUtil({customTesters: [tester]}),
|
||||
matcher = jasmineUnderTest.matchers.toContain(matchersUtil),
|
||||
result;
|
||||
|
||||
result = matcher.compare("ABC", "B");
|
||||
expect(util.contains).toHaveBeenCalledWith("ABC", "B", ['a', 'b']);
|
||||
result = matcher.compare(['1', '2'], 2);
|
||||
expect(result.pass).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -2,8 +2,10 @@ describe("toEqual", function() {
|
||||
"use strict";
|
||||
|
||||
function compareEquals(actual, expected) {
|
||||
var util = jasmineUnderTest.matchersUtil,
|
||||
matcher = jasmineUnderTest.matchers.toEqual(util);
|
||||
var matchersUtil = new jasmineUnderTest.MatchersUtil({
|
||||
pp: jasmineUnderTest.makePrettyPrinter()
|
||||
}),
|
||||
matcher = jasmineUnderTest.matchers.toEqual(matchersUtil);
|
||||
|
||||
var result = matcher.compare(actual, expected);
|
||||
|
||||
@@ -11,37 +13,32 @@ describe("toEqual", function() {
|
||||
}
|
||||
|
||||
it("delegates to equals function", function() {
|
||||
var util = {
|
||||
var matchersUtil = {
|
||||
equals: jasmine.createSpy('delegated-equals').and.returnValue(true),
|
||||
buildFailureMessage: function() {
|
||||
return 'does not matter'
|
||||
return 'does not matter';
|
||||
},
|
||||
DiffBuilder: jasmineUnderTest.matchersUtil.DiffBuilder
|
||||
DiffBuilder: new jasmineUnderTest.DiffBuilder()
|
||||
},
|
||||
matcher = jasmineUnderTest.matchers.toEqual(util),
|
||||
matcher = jasmineUnderTest.matchers.toEqual(matchersUtil),
|
||||
result;
|
||||
|
||||
result = matcher.compare(1, 1);
|
||||
|
||||
expect(util.equals).toHaveBeenCalledWith(1, 1, [], jasmine.anything());
|
||||
expect(matchersUtil.equals).toHaveBeenCalledWith(1, 1, jasmine.anything());
|
||||
expect(result.pass).toBe(true);
|
||||
});
|
||||
|
||||
it("delegates custom equality testers, if present", function() {
|
||||
var util = {
|
||||
equals: jasmine.createSpy('delegated-equals').and.returnValue(true),
|
||||
buildFailureMessage: function() {
|
||||
return 'does not matter'
|
||||
},
|
||||
DiffBuilder: jasmineUnderTest.matchersUtil.DiffBuilder
|
||||
it("works with custom equality testers", function() {
|
||||
var tester = function (a, b) {
|
||||
return a.toString() === b.toString();
|
||||
},
|
||||
customEqualityTesters = ['a', 'b'],
|
||||
matcher = jasmineUnderTest.matchers.toEqual(util, customEqualityTesters),
|
||||
matchersUtil = new jasmineUnderTest.MatchersUtil({customTesters: [tester]}),
|
||||
matcher = jasmineUnderTest.matchers.toEqual(matchersUtil),
|
||||
result;
|
||||
|
||||
result = matcher.compare(1, 1);
|
||||
result = matcher.compare(1, '1');
|
||||
|
||||
expect(util.equals).toHaveBeenCalledWith(1, 1, ['a', 'b'], jasmine.anything());
|
||||
expect(result.pass).toBe(true);
|
||||
});
|
||||
|
||||
@@ -100,16 +97,66 @@ describe("toEqual", function() {
|
||||
expect(compareEquals(actual, expected).message).toEqual(message);
|
||||
});
|
||||
|
||||
it("reports extra and missing properties together", function() {
|
||||
it("uses custom object formatters to pretty-print simple properties", function() {
|
||||
function formatter(x) {
|
||||
if (typeof x === 'number') {
|
||||
return '|' + x + '|';
|
||||
}
|
||||
}
|
||||
|
||||
var actual = {x: {y: 1, z: 2, f: 4}},
|
||||
expected = {x: {y: 1, z: 2, g: 3}},
|
||||
pp = jasmineUnderTest.makePrettyPrinter([formatter]),
|
||||
matchersUtil = new jasmineUnderTest.MatchersUtil({pp: pp}),
|
||||
matcher = jasmineUnderTest.matchers.toEqual(matchersUtil),
|
||||
message =
|
||||
"Expected $.x to have properties\n" +
|
||||
" g: 3\n" +
|
||||
" g: |3|\n" +
|
||||
"Expected $.x not to have properties\n" +
|
||||
" f: 4";
|
||||
" f: |4|";
|
||||
|
||||
expect(compareEquals(actual, expected).message).toEqual(message);
|
||||
expect(matcher.compare(actual, expected).message).toEqual(message);
|
||||
});
|
||||
|
||||
it("uses custom object formatters to show simple values in diffs", function() {
|
||||
function formatter(x) {
|
||||
if (typeof x === 'number') {
|
||||
return '|' + x + '|';
|
||||
}
|
||||
}
|
||||
|
||||
var actual = [{foo: 4}],
|
||||
expected = [{foo: 5}],
|
||||
prettyPrinter = jasmineUnderTest.makePrettyPrinter([formatter]),
|
||||
matchersUtil = new jasmineUnderTest.MatchersUtil({pp: prettyPrinter}),
|
||||
matcher = jasmineUnderTest.matchers.toEqual(matchersUtil),
|
||||
message = "Expected $[0].foo = |4| to equal |5|.";
|
||||
|
||||
expect(matcher.compare(actual, expected).message).toEqual(message);
|
||||
});
|
||||
|
||||
it("uses custom object formatters to show more complex objects diffs", function() {
|
||||
function formatter(x) {
|
||||
if (x.hasOwnProperty('a')) {
|
||||
return '[thing with a=' + x.a + ', b=' + x.b + ']';
|
||||
}
|
||||
}
|
||||
|
||||
var actual = [{
|
||||
foo: {a: 1, b: 2},
|
||||
bar: 'should not be pretty printed'
|
||||
}],
|
||||
expected = [{
|
||||
foo: {a: 5, b: 2},
|
||||
bar: "shouldn't be pretty printed"
|
||||
}],
|
||||
prettyPrinter = jasmineUnderTest.makePrettyPrinter([formatter]),
|
||||
matchersUtil = new jasmineUnderTest.MatchersUtil({pp: prettyPrinter}),
|
||||
matcher = jasmineUnderTest.matchers.toEqual(matchersUtil),
|
||||
message = "Expected $[0].foo = [thing with a=1, b=2] to equal [thing with a=5, b=2].\n" +
|
||||
"Expected $[0].bar = 'should not be pretty printed' to equal 'shouldn't be pretty printed'.";
|
||||
|
||||
expect(matcher.compare(actual, expected).message).toEqual(message);
|
||||
});
|
||||
|
||||
it("reports extra and missing properties of the root-level object", function() {
|
||||
@@ -282,12 +329,31 @@ describe("toEqual", function() {
|
||||
function Bar() {}
|
||||
|
||||
var actual = {x: new Foo()},
|
||||
expected = {x: new Bar()},
|
||||
message = "Expected $.x to be a kind of Bar, but was Foo({ }).";
|
||||
expected = {x: new Bar()},
|
||||
message = "Expected $.x to be a kind of Bar, but was Foo({ }).";
|
||||
|
||||
expect(compareEquals(actual, expected).message).toEqual(message);
|
||||
});
|
||||
|
||||
it("uses custom object formatters for the value but not the type when reporting objects with different constructors", function () {
|
||||
function Foo() {}
|
||||
function Bar() {}
|
||||
function formatter(x) {
|
||||
if (x instanceof Foo || x instanceof Bar) {
|
||||
return '|' + x + '|';
|
||||
}
|
||||
}
|
||||
|
||||
var actual = {x: new Foo()},
|
||||
expected = {x: new Bar()},
|
||||
message = "Expected $.x to be a kind of Bar, but was |[object Object]|.",
|
||||
pp = jasmineUnderTest.makePrettyPrinter([formatter]),
|
||||
matchersUtil = new jasmineUnderTest.MatchersUtil({pp: pp}),
|
||||
matcher = jasmineUnderTest.matchers.toEqual(matchersUtil);
|
||||
|
||||
expect(matcher.compare(actual, expected).message).toEqual(message);
|
||||
});
|
||||
|
||||
it("reports type mismatches at the root level", function () {
|
||||
function Foo() {}
|
||||
function Bar() {}
|
||||
@@ -299,6 +365,11 @@ describe("toEqual", function() {
|
||||
expect(compareEquals(actual, expected).message).toEqual(message);
|
||||
});
|
||||
|
||||
it("reports value mismatches at the root level", function() {
|
||||
expect(compareEquals(1, 2).message).toEqual("Expected 1 to equal 2.");
|
||||
});
|
||||
|
||||
|
||||
it("reports mismatches between objects with their own constructor property", function () {
|
||||
function Foo() {}
|
||||
function Bar() {}
|
||||
@@ -830,6 +901,24 @@ describe("toEqual", function() {
|
||||
expect(compareEquals(actual, expected).message).toEqual(message);
|
||||
});
|
||||
|
||||
it("uses custom object formatters when the actual array is longer", function() {
|
||||
function formatter(x) {
|
||||
if (typeof x === 'number') {
|
||||
return '|' + x + '|';
|
||||
}
|
||||
}
|
||||
|
||||
var actual = [1, 1, 2, 3, 5],
|
||||
expected = [1, 1, 2, 3],
|
||||
pp = jasmineUnderTest.makePrettyPrinter([formatter]),
|
||||
matchersUtil = new jasmineUnderTest.MatchersUtil({pp: pp}),
|
||||
matcher = jasmineUnderTest.matchers.toEqual(matchersUtil),
|
||||
message = 'Expected $.length = |5| to equal |4|.\n' +
|
||||
'Unexpected $[4] = |5| in array.';
|
||||
|
||||
expect(matcher.compare(actual, expected).message).toEqual(message);
|
||||
});
|
||||
|
||||
it("expected array is longer", function() {
|
||||
var actual = [1, 1, 2, 3],
|
||||
expected = [1, 1, 2, 3, 5],
|
||||
|
||||
@@ -1,23 +1,25 @@
|
||||
describe("toHaveBeenCalledBefore", function () {
|
||||
it("throws an exception when the actual is not a spy", function () {
|
||||
var matcher = jasmineUnderTest.matchers.toHaveBeenCalledBefore(),
|
||||
fn = function () {
|
||||
},
|
||||
spy = new jasmineUnderTest.Spy('a spy');
|
||||
describe("toHaveBeenCalledBefore", function() {
|
||||
it("throws an exception when the actual is not a spy", function() {
|
||||
var matcher = jasmineUnderTest.matchers.toHaveBeenCalledBefore({
|
||||
pp: jasmineUnderTest.makePrettyPrinter()
|
||||
}),
|
||||
fn = function() {},
|
||||
spy = new jasmineUnderTest.Env().createSpy('a spy');
|
||||
|
||||
expect(function () {
|
||||
matcher.compare(fn, spy)
|
||||
matcher.compare(fn, spy);
|
||||
}).toThrowError(Error, /Expected a spy, but got Function./);
|
||||
});
|
||||
|
||||
it("throws an exception when the expected is not a spy", function () {
|
||||
var matcher = jasmineUnderTest.matchers.toHaveBeenCalledBefore(),
|
||||
spy = new jasmineUnderTest.Spy('a spy'),
|
||||
fn = function () {
|
||||
};
|
||||
it("throws an exception when the expected is not a spy", function() {
|
||||
var matcher = jasmineUnderTest.matchers.toHaveBeenCalledBefore({
|
||||
pp: jasmineUnderTest.makePrettyPrinter()
|
||||
}),
|
||||
spy = new jasmineUnderTest.Env().createSpy('a spy'),
|
||||
fn = function() {};
|
||||
|
||||
expect(function () {
|
||||
matcher.compare(spy, fn)
|
||||
matcher.compare(spy, fn);
|
||||
}).toThrowError(Error, /Expected a spy, but got Function./);
|
||||
});
|
||||
|
||||
|
||||
@@ -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() {
|
||||
|
||||
@@ -1,10 +1,11 @@
|
||||
describe("toHaveBeenCalledWith", function() {
|
||||
|
||||
it("passes when the actual was called with matching parameters", function() {
|
||||
var util = {
|
||||
contains: jasmine.createSpy('delegated-contains').and.returnValue(true)
|
||||
var matchersUtil = {
|
||||
contains: jasmine.createSpy('delegated-contains').and.returnValue(true),
|
||||
pp: jasmineUnderTest.makePrettyPrinter()
|
||||
},
|
||||
matcher = jasmineUnderTest.matchers.toHaveBeenCalledWith(util),
|
||||
matcher = jasmineUnderTest.matchers.toHaveBeenCalledWith(matchersUtil),
|
||||
calledSpy = new jasmineUnderTest.Spy('called-spy'),
|
||||
result;
|
||||
|
||||
@@ -15,25 +16,24 @@ describe("toHaveBeenCalledWith", function() {
|
||||
expect(result.message()).toEqual("Expected spy called-spy not to have been called with:\n [ 'a', 'b' ]\nbut it was.");
|
||||
});
|
||||
|
||||
it("passes through the custom equality testers", function() {
|
||||
var util = {
|
||||
contains: jasmine.createSpy('delegated-contains').and.returnValue(true)
|
||||
},
|
||||
customEqualityTesters = [function() { return true; }],
|
||||
matcher = jasmineUnderTest.matchers.toHaveBeenCalledWith(util, customEqualityTesters),
|
||||
calledSpy = new jasmineUnderTest.Spy('called-spy');
|
||||
it("supports custom equality testers", function() {
|
||||
var customEqualityTesters = [function() { return true; }],
|
||||
matchersUtil = new jasmineUnderTest.MatchersUtil({customTesters: customEqualityTesters}),
|
||||
matcher = jasmineUnderTest.matchers.toHaveBeenCalledWith(matchersUtil),
|
||||
calledSpy = new jasmineUnderTest.Spy('called-spy'),
|
||||
result;
|
||||
|
||||
calledSpy('a', 'b');
|
||||
matcher.compare(calledSpy, 'a', 'b');
|
||||
|
||||
expect(util.contains).toHaveBeenCalledWith([['a', 'b']], ['a', 'b'], customEqualityTesters);
|
||||
result = matcher.compare(calledSpy, 'a', 'b');
|
||||
expect(result.pass).toBe(true);
|
||||
});
|
||||
|
||||
it("fails when the actual was not called", function() {
|
||||
var util = {
|
||||
contains: jasmine.createSpy('delegated-contains').and.returnValue(false)
|
||||
var matchersUtil = {
|
||||
contains: jasmine.createSpy('delegated-contains').and.returnValue(false),
|
||||
pp: jasmineUnderTest.makePrettyPrinter()
|
||||
},
|
||||
matcher = jasmineUnderTest.matchers.toHaveBeenCalledWith(util),
|
||||
matcher = jasmineUnderTest.matchers.toHaveBeenCalledWith(matchersUtil),
|
||||
uncalledSpy = new jasmineUnderTest.Spy('uncalled spy'),
|
||||
result;
|
||||
|
||||
@@ -43,8 +43,8 @@ describe("toHaveBeenCalledWith", function() {
|
||||
});
|
||||
|
||||
it("fails when the actual was called with different parameters", function() {
|
||||
var util = jasmineUnderTest.matchersUtil,
|
||||
matcher = jasmineUnderTest.matchers.toHaveBeenCalledWith(util),
|
||||
var matchersUtil = new jasmineUnderTest.MatchersUtil({pp: jasmineUnderTest.makePrettyPrinter()}),
|
||||
matcher = jasmineUnderTest.matchers.toHaveBeenCalledWith(matchersUtil),
|
||||
calledSpy = new jasmineUnderTest.Spy('called spy'),
|
||||
result;
|
||||
|
||||
@@ -73,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./);
|
||||
});
|
||||
|
||||
@@ -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');
|
||||
|
||||
@@ -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");
|
||||
},
|
||||
@@ -180,10 +192,7 @@ describe("toThrowError", function() {
|
||||
});
|
||||
|
||||
it("passes if thrown is an Error and the expected the same Error", function() {
|
||||
var util = {
|
||||
equals: jasmine.createSpy('delegated-equal').and.returnValue(true)
|
||||
},
|
||||
matcher = jasmineUnderTest.matchers.toThrowError(),
|
||||
var matcher = jasmineUnderTest.matchers.toThrowError(),
|
||||
fn = function() {
|
||||
throw new Error();
|
||||
},
|
||||
@@ -196,10 +205,7 @@ describe("toThrowError", function() {
|
||||
});
|
||||
|
||||
it("passes if thrown is a custom error that takes arguments and the expected is the same error", function() {
|
||||
var util = {
|
||||
equals: jasmine.createSpy('delegated-equal').and.returnValue(true)
|
||||
},
|
||||
matcher = jasmineUnderTest.matchers.toThrowError(),
|
||||
var matcher = jasmineUnderTest.matchers.toThrowError(),
|
||||
CustomError = function CustomError(arg) { arg.x },
|
||||
fn = function() {
|
||||
throw new CustomError({ x: 1 });
|
||||
@@ -215,10 +221,7 @@ describe("toThrowError", function() {
|
||||
});
|
||||
|
||||
it("fails if thrown is an Error and the expected is a different Error", function() {
|
||||
var util = {
|
||||
equals: jasmine.createSpy('delegated-equal').and.returnValue(false)
|
||||
},
|
||||
matcher = jasmineUnderTest.matchers.toThrowError(),
|
||||
var matcher = jasmineUnderTest.matchers.toThrowError(),
|
||||
fn = function() {
|
||||
throw new Error();
|
||||
},
|
||||
@@ -231,10 +234,11 @@ 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)
|
||||
var matchersUtil = {
|
||||
equals: jasmine.createSpy('delegated-equal').and.returnValue(true),
|
||||
pp: jasmineUnderTest.makePrettyPrinter()
|
||||
},
|
||||
matcher = jasmineUnderTest.matchers.toThrowError(),
|
||||
matcher = jasmineUnderTest.matchers.toThrowError(matchersUtil),
|
||||
fn = function() {
|
||||
throw new TypeError("foo");
|
||||
},
|
||||
@@ -247,11 +251,12 @@ 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)
|
||||
var matchersUtil = {
|
||||
equals: jasmine.createSpy('delegated-equal').and.returnValue(true),
|
||||
pp: jasmineUnderTest.makePrettyPrinter()
|
||||
},
|
||||
matcher = jasmineUnderTest.matchers.toThrowError(),
|
||||
CustomError = function CustomError(arg) { this.message = arg.message },
|
||||
matcher = jasmineUnderTest.matchers.toThrowError(matchersUtil),
|
||||
CustomError = function CustomError(arg) { this.message = arg.message; },
|
||||
fn = function() {
|
||||
throw new CustomError({message: "foo"});
|
||||
},
|
||||
@@ -266,10 +271,11 @@ 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)
|
||||
var matchersUtil = {
|
||||
equals: jasmine.createSpy('delegated-equal').and.returnValue(false),
|
||||
pp: jasmineUnderTest.makePrettyPrinter()
|
||||
},
|
||||
matcher = jasmineUnderTest.matchers.toThrowError(),
|
||||
matcher = jasmineUnderTest.matchers.toThrowError(matchersUtil),
|
||||
fn = function() {
|
||||
throw new TypeError("foo");
|
||||
},
|
||||
@@ -282,10 +288,11 @@ 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)
|
||||
var matchersUtil = {
|
||||
equals: jasmine.createSpy('delegated-equal').and.returnValue(true),
|
||||
pp: jasmineUnderTest.makePrettyPrinter()
|
||||
},
|
||||
matcher = jasmineUnderTest.matchers.toThrowError(),
|
||||
matcher = jasmineUnderTest.matchers.toThrowError(matchersUtil),
|
||||
fn = function() {
|
||||
throw new TypeError("foo");
|
||||
},
|
||||
@@ -298,10 +305,11 @@ 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)
|
||||
var matchersUtil = {
|
||||
equals: jasmine.createSpy('delegated-equal').and.returnValue(false),
|
||||
pp: jasmineUnderTest.makePrettyPrinter()
|
||||
},
|
||||
matcher = jasmineUnderTest.matchers.toThrowError(),
|
||||
matcher = jasmineUnderTest.matchers.toThrowError(matchersUtil),
|
||||
fn = function() {
|
||||
throw new TypeError("foo");
|
||||
},
|
||||
|
||||
@@ -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");
|
||||
},
|
||||
|
||||
@@ -23,10 +23,11 @@ describe("toThrow", function() {
|
||||
});
|
||||
|
||||
it("passes if it throws but there is no expected", function() {
|
||||
var util = {
|
||||
equals: jasmine.createSpy('delegated-equal').and.returnValue(true)
|
||||
var matchersUtil = {
|
||||
equals: jasmine.createSpy('delegated-equal').and.returnValue(true),
|
||||
pp: jasmineUnderTest.makePrettyPrinter()
|
||||
},
|
||||
matcher = jasmineUnderTest.matchers.toThrow(util),
|
||||
matcher = jasmineUnderTest.matchers.toThrow(matchersUtil),
|
||||
fn = function() {
|
||||
throw 5;
|
||||
},
|
||||
@@ -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;
|
||||
},
|
||||
@@ -51,10 +54,11 @@ 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)
|
||||
var matchersUtil = {
|
||||
equals: jasmine.createSpy('delegated-equal').and.returnValue(true),
|
||||
pp: jasmineUnderTest.makePrettyPrinter()
|
||||
},
|
||||
matcher = jasmineUnderTest.matchers.toThrow(util),
|
||||
matcher = jasmineUnderTest.matchers.toThrow(matchersUtil),
|
||||
fn = function() {
|
||||
throw 5;
|
||||
},
|
||||
@@ -67,10 +71,11 @@ 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)
|
||||
var matchersUtil = {
|
||||
equals: jasmine.createSpy('delegated-equal').and.returnValue(false),
|
||||
pp: jasmineUnderTest.makePrettyPrinter()
|
||||
},
|
||||
matcher = jasmineUnderTest.matchers.toThrow(util),
|
||||
matcher = jasmineUnderTest.matchers.toThrow(matchersUtil),
|
||||
fn = function() {
|
||||
throw 5;
|
||||
},
|
||||
@@ -83,10 +88,11 @@ 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)
|
||||
var matchersUtil = {
|
||||
equals: jasmine.createSpy('delegated-equal').and.returnValue(false),
|
||||
pp: jasmineUnderTest.makePrettyPrinter()
|
||||
},
|
||||
matcher = jasmineUnderTest.matchers.toThrow(util),
|
||||
matcher = jasmineUnderTest.matchers.toThrow(matchersUtil),
|
||||
fn = function() {
|
||||
throw 5;
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user