Merge branch 'main' into 3.99

This commit is contained in:
Steve Gravrock
2020-09-14 18:39:32 -07:00
82 changed files with 2725 additions and 1286 deletions

View File

@@ -133,4 +133,50 @@ describe("DiffBuilder", function () {
expect(diffBuilder.getMessage()).toEqual(expectedMsg);
});
it('builds diffs involving asymmetric equality testers that implement valuesForDiff_ at the root', function() {
var prettyPrinter = jasmineUnderTest.makePrettyPrinter([]),
diffBuilder = new jasmineUnderTest.DiffBuilder({prettyPrinter: prettyPrinter}),
expectedMsg = 'Expected $.foo = 1 to equal 2.\n' +
"Expected $.baz = undefined to equal 3.";
diffBuilder.setRoots(
{foo: 1, bar: 2},
jasmine.objectContaining({foo: 2, baz: 3})
);
diffBuilder.withPath('foo', function() {
diffBuilder.recordMismatch();
});
diffBuilder.withPath('baz', function() {
diffBuilder.recordMismatch();
});
expect(diffBuilder.getMessage()).toEqual(expectedMsg);
});
it('builds diffs involving asymmetric equality testers that implement valuesForDiff_ below the root', function() {
var prettyPrinter = jasmineUnderTest.makePrettyPrinter([]),
diffBuilder = new jasmineUnderTest.DiffBuilder({prettyPrinter: prettyPrinter}),
expectedMsg = 'Expected $.x.foo = 1 to equal 2.\n' +
"Expected $.x.baz = undefined to equal 3.";
diffBuilder.setRoots(
{x: {foo: 1, bar: 2}},
{x: jasmine.objectContaining({foo: 2, baz: 3})}
);
diffBuilder.withPath('x', function() {
diffBuilder.withPath('foo', function () {
diffBuilder.recordMismatch();
});
diffBuilder.withPath('baz', function () {
diffBuilder.recordMismatch();
});
});
expect(diffBuilder.getMessage()).toEqual(expectedMsg);
});
});

View File

@@ -0,0 +1,52 @@
/* eslint-disable compat/compat */
describe('toBePending', function() {
it('passes if the actual promise is pending', function() {
jasmine.getEnv().requirePromises();
var matchersUtil = new jasmineUnderTest.MatchersUtil(),
matcher = jasmineUnderTest.asyncMatchers.toBePending(matchersUtil),
actual = new Promise(function() {});
return matcher.compare(actual).then(function(result) {
expect(result).toEqual(jasmine.objectContaining({pass: true}));
});
});
it('fails if the actual promise is resolved', function() {
jasmine.getEnv().requirePromises();
var matchersUtil = new jasmineUnderTest.MatchersUtil(),
matcher = jasmineUnderTest.asyncMatchers.toBePending(matchersUtil),
actual = Promise.resolve();
return matcher.compare(actual).then(function(result) {
expect(result).toEqual(jasmine.objectContaining({pass: false}));
});
});
it('fails if the actual promise is rejected', function() {
jasmine.getEnv().requirePromises();
var matchersUtil = new jasmineUnderTest.MatchersUtil(),
matcher = jasmineUnderTest.asyncMatchers.toBePending(matchersUtil),
actual = Promise.reject(new Error('promise was rejected'));
return matcher.compare(actual).then(function(result) {
expect(result).toEqual(jasmine.objectContaining({pass: false}));
});
});
it('fails if actual is not a promise', function() {
var matchersUtil = new jasmineUnderTest.MatchersUtil(),
matcher = jasmineUnderTest.asyncMatchers.toBePending(matchersUtil),
actual = 'not a promise';
function f() {
return matcher.compare(actual);
}
expect(f).toThrowError(
'Expected toBePending to be called on a promise.'
);
});
});

View File

@@ -1,3 +1,4 @@
/* eslint-disable compat/compat */
describe('toBeRejected', function() {
it('passes if the actual is rejected', function() {
jasmine.getEnv().requirePromises();

View File

@@ -1,8 +1,9 @@
/* eslint-disable compat/compat */
describe('#toBeRejectedWithError', function () {
it('passes when Error type matches', function () {
jasmine.getEnv().requirePromises();
var matchersUtil = new jasmineUnderTest.MatchersUtil({pp: new jasmineUnderTest.makePrettyPrinter()}),
var matchersUtil = new jasmineUnderTest.MatchersUtil({pp: jasmineUnderTest.makePrettyPrinter()}),
matcher = jasmineUnderTest.asyncMatchers.toBeRejectedWithError(matchersUtil),
actual = Promise.reject(new TypeError('foo'));
@@ -17,7 +18,7 @@ describe('#toBeRejectedWithError', function () {
it('passes when Error type and message matches', function () {
jasmine.getEnv().requirePromises();
var matchersUtil = new jasmineUnderTest.MatchersUtil({pp: new jasmineUnderTest.makePrettyPrinter()}),
var matchersUtil = new jasmineUnderTest.MatchersUtil({pp: jasmineUnderTest.makePrettyPrinter()}),
matcher = jasmineUnderTest.asyncMatchers.toBeRejectedWithError(matchersUtil),
actual = Promise.reject(new TypeError('foo'));
@@ -32,7 +33,7 @@ describe('#toBeRejectedWithError', function () {
it('passes when Error matches and is exactly Error', function() {
jasmine.getEnv().requirePromises();
var matchersUtil = new jasmineUnderTest.MatchersUtil({pp: new jasmineUnderTest.makePrettyPrinter()}),
var matchersUtil = new jasmineUnderTest.MatchersUtil({pp: jasmineUnderTest.makePrettyPrinter()}),
matcher = jasmineUnderTest.asyncMatchers.toBeRejectedWithError(matchersUtil),
actual = Promise.reject(new Error());
@@ -48,7 +49,7 @@ describe('#toBeRejectedWithError', function () {
it('passes when Error message matches a string', function () {
jasmine.getEnv().requirePromises();
var matchersUtil = new jasmineUnderTest.MatchersUtil({pp: new jasmineUnderTest.makePrettyPrinter()}),
var matchersUtil = new jasmineUnderTest.MatchersUtil({pp: jasmineUnderTest.makePrettyPrinter()}),
matcher = jasmineUnderTest.asyncMatchers.toBeRejectedWithError(matchersUtil),
actual = Promise.reject(new Error('foo'));
@@ -63,7 +64,7 @@ describe('#toBeRejectedWithError', function () {
it('passes when Error message matches a RegExp', function () {
jasmine.getEnv().requirePromises();
var matchersUtil = new jasmineUnderTest.MatchersUtil({pp: new jasmineUnderTest.makePrettyPrinter()}),
var matchersUtil = new jasmineUnderTest.MatchersUtil({pp: jasmineUnderTest.makePrettyPrinter()}),
matcher = jasmineUnderTest.asyncMatchers.toBeRejectedWithError(matchersUtil),
actual = Promise.reject(new Error('foo'));
@@ -78,7 +79,7 @@ describe('#toBeRejectedWithError', function () {
it('passes when Error message is empty', function () {
jasmine.getEnv().requirePromises();
var matchersUtil = new jasmineUnderTest.MatchersUtil({pp: new jasmineUnderTest.makePrettyPrinter()}),
var matchersUtil = new jasmineUnderTest.MatchersUtil({pp: jasmineUnderTest.makePrettyPrinter()}),
matcher = jasmineUnderTest.asyncMatchers.toBeRejectedWithError(matchersUtil),
actual = Promise.reject(new Error());
@@ -93,7 +94,7 @@ describe('#toBeRejectedWithError', function () {
it('passes when no arguments', function () {
jasmine.getEnv().requirePromises();
var matchersUtil = new jasmineUnderTest.MatchersUtil({pp: new jasmineUnderTest.makePrettyPrinter()}),
var matchersUtil = new jasmineUnderTest.MatchersUtil({pp: jasmineUnderTest.makePrettyPrinter()}),
matcher = jasmineUnderTest.asyncMatchers.toBeRejectedWithError(matchersUtil),
actual = Promise.reject(new Error());
@@ -108,7 +109,7 @@ describe('#toBeRejectedWithError', function () {
it('fails when resolved', function () {
jasmine.getEnv().requirePromises();
var matchersUtil = new jasmineUnderTest.MatchersUtil({pp: new jasmineUnderTest.makePrettyPrinter()}),
var matchersUtil = new jasmineUnderTest.MatchersUtil({pp: jasmineUnderTest.makePrettyPrinter()}),
matcher = jasmineUnderTest.asyncMatchers.toBeRejectedWithError(matchersUtil),
actual = Promise.resolve(new Error('foo'));
@@ -123,7 +124,7 @@ describe('#toBeRejectedWithError', function () {
it('fails when rejected with non Error type', function () {
jasmine.getEnv().requirePromises();
var matchersUtil = new jasmineUnderTest.MatchersUtil({pp: new jasmineUnderTest.makePrettyPrinter()}),
var matchersUtil = new jasmineUnderTest.MatchersUtil({pp: jasmineUnderTest.makePrettyPrinter()}),
matcher = jasmineUnderTest.asyncMatchers.toBeRejectedWithError(matchersUtil),
actual = Promise.reject('foo');
@@ -138,7 +139,7 @@ describe('#toBeRejectedWithError', function () {
it('fails when Error type mismatches', function () {
jasmine.getEnv().requirePromises();
var matchersUtil = new jasmineUnderTest.MatchersUtil({pp: new jasmineUnderTest.makePrettyPrinter()}),
var matchersUtil = new jasmineUnderTest.MatchersUtil({pp: jasmineUnderTest.makePrettyPrinter()}),
matcher = jasmineUnderTest.asyncMatchers.toBeRejectedWithError(matchersUtil),
actual = Promise.reject(new Error('foo'));
@@ -153,7 +154,7 @@ describe('#toBeRejectedWithError', function () {
it('fails when Error message mismatches', function () {
jasmine.getEnv().requirePromises();
var matchersUtil = new jasmineUnderTest.MatchersUtil({pp: new jasmineUnderTest.makePrettyPrinter()}),
var matchersUtil = new jasmineUnderTest.MatchersUtil({pp: jasmineUnderTest.makePrettyPrinter()}),
matcher = jasmineUnderTest.asyncMatchers.toBeRejectedWithError(matchersUtil),
actual = Promise.reject(new Error('foo'));
@@ -166,7 +167,7 @@ describe('#toBeRejectedWithError', function () {
});
it('fails if actual is not a promise', function() {
var matchersUtil = new jasmineUnderTest.MatchersUtil({pp: new jasmineUnderTest.makePrettyPrinter()}),
var matchersUtil = new jasmineUnderTest.MatchersUtil({pp: jasmineUnderTest.makePrettyPrinter()}),
matcher = jasmineUnderTest.asyncMatchers.toBeRejectedWithError(matchersUtil),
actual = 'not a promise';

View File

@@ -1,3 +1,4 @@
/* eslint-disable compat/compat */
describe('#toBeRejectedWith', function () {
it('should return true if the promise is rejected with the expected value', function () {
jasmine.getEnv().requirePromises();

View File

@@ -1,3 +1,4 @@
/* eslint-disable compat/compat */
describe('toBeResolved', function() {
it('passes if the actual is resolved', function() {
jasmine.getEnv().requirePromises();

View File

@@ -1,3 +1,4 @@
/* eslint-disable compat/compat */
describe('#toBeResolvedTo', function() {
it('passes if the promise is resolved to the expected value', function() {
jasmine.getEnv().requirePromises();
@@ -14,7 +15,7 @@ describe('#toBeResolvedTo', function() {
it('fails if the promise is rejected', function() {
jasmine.getEnv().requirePromises();
var matchersUtil = new jasmineUnderTest.MatchersUtil({pp: new jasmineUnderTest.makePrettyPrinter()}),
var matchersUtil = new jasmineUnderTest.MatchersUtil({pp: jasmineUnderTest.makePrettyPrinter()}),
matcher = jasmineUnderTest.asyncMatchers.toBeResolvedTo(matchersUtil),
actual = Promise.reject('AsyncExpectationSpec error');
@@ -29,7 +30,7 @@ describe('#toBeResolvedTo', function() {
it('fails if the promise is resolved to a different value', function() {
jasmine.getEnv().requirePromises();
var matchersUtil = new jasmineUnderTest.MatchersUtil({pp: new jasmineUnderTest.makePrettyPrinter()}),
var matchersUtil = new jasmineUnderTest.MatchersUtil({pp: jasmineUnderTest.makePrettyPrinter()}),
matcher = jasmineUnderTest.asyncMatchers.toBeResolvedTo(matchersUtil),
actual = Promise.resolve({foo: 17});
@@ -44,7 +45,7 @@ describe('#toBeResolvedTo', function() {
it('builds its message correctly when negated', function() {
jasmine.getEnv().requirePromises();
var matchersUtil = new jasmineUnderTest.MatchersUtil({pp: new jasmineUnderTest.makePrettyPrinter()}),
var matchersUtil = new jasmineUnderTest.MatchersUtil({pp: jasmineUnderTest.makePrettyPrinter()}),
matcher = jasmineUnderTest.asyncMatchers.toBeResolvedTo(matchersUtil),
actual = Promise.resolve(true);

View File

@@ -112,6 +112,11 @@ describe("matchersUtil", function() {
expect(matchersUtil.equals(123, 456)).toBe(false);
});
it("fails for a Number and a String that have equivalent values", function() {
var matchersUtil = new jasmineUnderTest.MatchersUtil();
expect(matchersUtil.equals(123, "123")).toBe(false);
});
it("passes for Dates that are equivalent", function() {
var matchersUtil = new jasmineUnderTest.MatchersUtil();
expect(matchersUtil.equals(new Date("Jan 1, 1970"), new Date("Jan 1, 1970"))).toBe(true);
@@ -280,8 +285,8 @@ describe("matchersUtil", function() {
it("passes for equivalent Promises (GitHub issue #1314)", function() {
if (typeof Promise === 'undefined') { return; }
var p1 = new Promise(function () {}),
p2 = new Promise(function () {}),
var p1 = new Promise(function () {}), // eslint-disable-line compat/compat
p2 = new Promise(function () {}), // eslint-disable-line compat/compat
matchersUtil = new jasmineUnderTest.MatchersUtil();
expect(matchersUtil.equals(p1, p1)).toBe(true);
@@ -416,10 +421,10 @@ describe("matchersUtil", function() {
jasmine.getEnv().requireFunctioningMaps();
var matchersUtil = new jasmineUnderTest.MatchersUtil();
var obj = new Map();
var obj = new Map(); // eslint-disable-line compat/compat
obj.set(1, 2);
obj.set('foo', 'bar');
var containing = new jasmineUnderTest.MapContaining(new Map());
var containing = new jasmineUnderTest.MapContaining(new Map()); // eslint-disable-line compat/compat
containing.sample.set('foo', 'bar');
expect(matchersUtil.equals(obj, containing)).toBe(true);
@@ -430,10 +435,10 @@ describe("matchersUtil", function() {
jasmine.getEnv().requireFunctioningSets();
var matchersUtil = new jasmineUnderTest.MatchersUtil();
var obj = new Set();
var obj = new Set(); // eslint-disable-line compat/compat
obj.add(1);
obj.add('foo');
var containing = new jasmineUnderTest.SetContaining(new Set());
var containing = new jasmineUnderTest.SetContaining(new Set()); // eslint-disable-line compat/compat
containing.sample.add(1);
expect(matchersUtil.equals(obj, containing)).toBe(true);
@@ -610,17 +615,17 @@ describe("matchersUtil", function() {
it("passes when comparing two empty sets", function() {
jasmine.getEnv().requireFunctioningSets();
var matchersUtil = new jasmineUnderTest.MatchersUtil();
expect(matchersUtil.equals(new Set(), new Set())).toBe(true);
expect(matchersUtil.equals(new Set(), new Set())).toBe(true); // eslint-disable-line compat/compat
});
it("passes when comparing identical sets", function() {
jasmine.getEnv().requireFunctioningSets();
var matchersUtil = new jasmineUnderTest.MatchersUtil();
var setA = new Set();
var setA = new Set(); // eslint-disable-line compat/compat
setA.add(6);
setA.add(5);
var setB = new Set();
var setB = new Set(); // eslint-disable-line compat/compat
setB.add(6);
setB.add(5);
@@ -631,10 +636,10 @@ describe("matchersUtil", function() {
jasmine.getEnv().requireFunctioningSets();
var matchersUtil = new jasmineUnderTest.MatchersUtil();
var setA = new Set();
var setA = new Set(); // eslint-disable-line compat/compat
setA.add(3);
setA.add(6);
var setB = new Set();
var setB = new Set(); // eslint-disable-line compat/compat
setB.add(6);
setB.add(3);
@@ -645,24 +650,23 @@ describe("matchersUtil", function() {
jasmine.getEnv().requireFunctioningSets();
var matchersUtil = new jasmineUnderTest.MatchersUtil();
var setA1 = new Set();
var setA1 = new Set(); // eslint-disable-line compat/compat
setA1.add(['a',3]);
setA1.add([6,1]);
var setA2 = new Set();
var setA2 = new Set(); // eslint-disable-line compat/compat
setA1.add(['y',3]);
setA1.add([6,1]);
var setA = new Set();
var setA = new Set(); // eslint-disable-line compat/compat
setA.add(setA1);
setA.add(setA2);
var setB1 = new Set();
var setB1 = new Set(); // eslint-disable-line compat/compat
setB1.add([6,1]);
setB1.add(['a',3]);
var setB2 = new Set();
var setB2 = new Set(); // eslint-disable-line compat/compat
setB1.add([6,1]);
setB1.add(['y',3]);
var setB = new Set();
var setB = new Set(); // eslint-disable-line compat/compat
setB.add(setB1);
setB.add(setB2);
@@ -673,10 +677,10 @@ describe("matchersUtil", function() {
jasmine.getEnv().requireFunctioningSets();
var matchersUtil = new jasmineUnderTest.MatchersUtil();
var setA = new Set();
var setA = new Set(); // eslint-disable-line compat/compat
setA.add([[1,2], [3,4]]);
setA.add([[5,6], [7,8]]);
var setB = new Set();
var setB = new Set(); // eslint-disable-line compat/compat
setB.add([[5,6], [7,8]]);
setB.add([[1,2], [3,4]]);
@@ -686,11 +690,11 @@ describe("matchersUtil", function() {
it("fails for sets with different elements", function() {
jasmine.getEnv().requireFunctioningSets();
var matchersUtil = new jasmineUnderTest.MatchersUtil();
var setA = new Set();
var setA = new Set(); // eslint-disable-line compat/compat
setA.add(6);
setA.add(3);
setA.add(5);
var setB = new Set();
var setB = new Set(); // eslint-disable-line compat/compat
setB.add(6);
setB.add(4);
setB.add(5);
@@ -701,10 +705,10 @@ describe("matchersUtil", function() {
it("fails for sets of different size", function() {
jasmine.getEnv().requireFunctioningSets();
var matchersUtil = new jasmineUnderTest.MatchersUtil();
var setA = new Set();
var setA = new Set(); // eslint-disable-line compat/compat
setA.add(6);
setA.add(3);
var setB = new Set();
var setB = new Set(); // eslint-disable-line compat/compat
setB.add(6);
setB.add(4);
setB.add(5);
@@ -715,15 +719,15 @@ describe("matchersUtil", function() {
it("passes when comparing two empty maps", function() {
jasmine.getEnv().requireFunctioningMaps();
var matchersUtil = new jasmineUnderTest.MatchersUtil();
expect(matchersUtil.equals(new Map(), new Map())).toBe(true);
expect(matchersUtil.equals(new Map(), new Map())).toBe(true); // eslint-disable-line compat/compat
});
it("passes when comparing identical maps", function() {
jasmine.getEnv().requireFunctioningMaps();
var matchersUtil = new jasmineUnderTest.MatchersUtil();
var mapA = new Map();
var mapA = new Map(); // eslint-disable-line compat/compat
mapA.set(6, 5);
var mapB = new Map();
var mapB = new Map(); // eslint-disable-line compat/compat
mapB.set(6, 5);
expect(matchersUtil.equals(mapA, mapB)).toBe(true);
});
@@ -731,10 +735,10 @@ describe("matchersUtil", function() {
it("passes when comparing identical maps with different insertion order", function() {
jasmine.getEnv().requireFunctioningMaps();
var matchersUtil = new jasmineUnderTest.MatchersUtil();
var mapA = new Map();
var mapA = new Map(); // eslint-disable-line compat/compat
mapA.set("a", 3);
mapA.set(6, 1);
var mapB = new Map();
var mapB = new Map(); // eslint-disable-line compat/compat
mapB.set(6, 1);
mapB.set("a", 3);
expect(matchersUtil.equals(mapA, mapB)).toBe(true);
@@ -743,10 +747,10 @@ describe("matchersUtil", function() {
it("fails for maps with different elements", function() {
jasmine.getEnv().requireFunctioningMaps();
var matchersUtil = new jasmineUnderTest.MatchersUtil();
var mapA = new Map();
var mapA = new Map(); // eslint-disable-line compat/compat
mapA.set(6, 3);
mapA.set(5, 1);
var mapB = new Map();
var mapB = new Map(); // eslint-disable-line compat/compat
mapB.set(6, 4);
mapB.set(5, 1);
@@ -756,9 +760,9 @@ describe("matchersUtil", function() {
it("fails for maps of different size", function() {
jasmine.getEnv().requireFunctioningMaps();
var matchersUtil = new jasmineUnderTest.MatchersUtil();
var mapA = new Map();
var mapA = new Map(); // eslint-disable-line compat/compat
mapA.set(6, 3);
var mapB = new Map();
var mapB = new Map(); // eslint-disable-line compat/compat
mapB.set(6, 4);
mapB.set(5, 1);
expect(matchersUtil.equals(mapA, mapB)).toBe(false);
@@ -829,7 +833,7 @@ describe("matchersUtil", function() {
expect(diffBuilder.setRoots).toHaveBeenCalledWith(actual, expected);
expect(diffBuilder.withPath).toHaveBeenCalledWith('x', jasmine.any(Function));
expect(diffBuilder.recordMismatch). toHaveBeenCalledWith();
expect(diffBuilder.recordMismatch).toHaveBeenCalledWith();
});
it("records both objects when the tester does not implement valuesForDiff", function() {
@@ -846,7 +850,7 @@ describe("matchersUtil", function() {
expect(diffBuilder.setRoots).toHaveBeenCalledWith(actual, expected);
expect(diffBuilder.withPath).toHaveBeenCalledWith('x', jasmine.any(Function));
expect(diffBuilder.recordMismatch). toHaveBeenCalledWith();
expect(diffBuilder.recordMismatch).toHaveBeenCalledWith();
});
});
@@ -981,7 +985,7 @@ describe("matchersUtil", function() {
var matchersUtil = new jasmineUnderTest.MatchersUtil();
var setItem = {'foo': 'bar'};
var set = new Set();
var set = new Set(); // eslint-disable-line compat/compat
set.add(setItem);
expect(matchersUtil.contains(set, setItem)).toBe(true);
@@ -992,7 +996,7 @@ describe("matchersUtil", function() {
jasmine.getEnv().requireFunctioningSets();
var matchersUtil = new jasmineUnderTest.MatchersUtil();
var set = new Set();
var set = new Set(); // eslint-disable-line compat/compat
set.add({'foo': 'bar'});
expect(matchersUtil.contains(set, {'foo': 'bar'})).toBe(false);

View File

@@ -261,8 +261,8 @@ describe("toEqual", function() {
it("reports mismatches between arrays of different types", function() {
jasmine.getEnv().requireFunctioningTypedArrays();
var actual = new Uint32Array([1, 2, 3]),
expected = new Uint16Array([1, 2, 3]),
var actual = new Uint32Array([1, 2, 3]), // eslint-disable-line compat/compat
expected = new Uint16Array([1, 2, 3]), // eslint-disable-line compat/compat
message = "Expected Uint32Array [ 1, 2, 3 ] to equal Uint16Array [ 1, 2, 3 ].";
expect(compareEquals(actual, expected).message).toEqual(message);
@@ -429,17 +429,30 @@ describe("toEqual", function() {
expect(compareEquals(actual, expected).message).toEqual(message);
});
it("reports mismatches involving objectContaining and an object", function() {
var actual = {x: {a: 1, b: 4, c: 3, extra: 'ignored'}};
var expected = {x: jasmineUnderTest.objectContaining({a: 1, b: 2, c: 3})};
expect(compareEquals(actual, expected).message).toEqual('Expected $.x.b = 4 to equal 2.');
it('reports mismatches between an object and objectContaining', function() {
var actual = {a: 1, b: 4, c: 3, extra: 'ignored'};
var expected = jasmineUnderTest.objectContaining({a: 1, b: 2, c: 3, d: 4});
expect(compareEquals(actual, expected).message)
.toEqual(
'Expected $.b = 4 to equal 2.\n' +
'Expected $.d = undefined to equal 4.'
);
});
it("reports mismatches between a non-object and objectContaining", function() {
var actual = {x: 1};
var expected = {x: jasmineUnderTest.objectContaining({a: 1})};
var actual = 1;
var expected = jasmineUnderTest.objectContaining({a: 1});
expect(compareEquals(actual, expected).message).toEqual(
"Expected $.x = 1 to equal '<jasmine.objectContaining(Object({ a: 1 }))>'."
"Expected 1 to equal '<jasmine.objectContaining(Object({ a: 1 }))>'."
);
});
it("reports mismatches involving a nested objectContaining", function() {
var actual = {x: {a: 1, b: 4, c: 3, extra: 'ignored'}};
var expected = {x: jasmineUnderTest.objectContaining({a: 1, b: 2, c: 3, d: 4})};
expect(compareEquals(actual, expected).message).toEqual(
'Expected $.x.b = 4 to equal 2.\n' +
'Expected $.x.d = undefined to equal 4.'
);
});
@@ -448,9 +461,9 @@ describe("toEqual", function() {
it("reports mismatches between Sets", function() {
jasmine.getEnv().requireFunctioningSets();
var actual = new Set();
var actual = new Set(); // eslint-disable-line compat/compat
actual.add(1);
var expected = new Set();
var expected = new Set(); // eslint-disable-line compat/compat
expected.add(2);
var message = 'Expected Set( 1 ) to equal Set( 2 ).';
@@ -460,9 +473,9 @@ describe("toEqual", function() {
it("reports deep mismatches within Sets", function() {
jasmine.getEnv().requireFunctioningSets();
var actual = new Set();
var actual = new Set(); // eslint-disable-line compat/compat
actual.add({x: 1});
var expected = new Set();
var expected = new Set(); // eslint-disable-line compat/compat
expected.add({x: 2});
var message = 'Expected Set( Object({ x: 1 }) ) to equal Set( Object({ x: 2 }) ).';
@@ -472,9 +485,9 @@ describe("toEqual", function() {
it("reports mismatches between Sets nested in objects", function() {
jasmine.getEnv().requireFunctioningSets();
var actualSet = new Set();
var actualSet = new Set(); // eslint-disable-line compat/compat
actualSet.add(1);
var expectedSet = new Set();
var expectedSet = new Set(); // eslint-disable-line compat/compat
expectedSet.add(2);
var actual = { sets: [actualSet] };
@@ -487,10 +500,10 @@ describe("toEqual", function() {
it("reports mismatches between Sets of different lengths", function() {
jasmine.getEnv().requireFunctioningSets();
var actual = new Set();
var actual = new Set(); // eslint-disable-line compat/compat
actual.add(1);
actual.add(2);
var expected = new Set();
var expected = new Set(); // eslint-disable-line compat/compat
expected.add(2);
var message = 'Expected Set( 1, 2 ) to equal Set( 2 ).';
@@ -501,10 +514,10 @@ describe("toEqual", function() {
jasmine.getEnv().requireFunctioningSets();
// Use 'duplicate' object in actual so sizes match
var actual = new Set();
var actual = new Set(); // eslint-disable-line compat/compat
actual.add({x: 1});
actual.add({x: 1});
var expected = new Set();
var expected = new Set(); // eslint-disable-line compat/compat
expected.add({x: 1});
expected.add({x: 2});
var message = 'Expected Set( Object({ x: 1 }), Object({ x: 1 }) ) to equal Set( Object({ x: 1 }), Object({ x: 2 }) ).';
@@ -516,10 +529,10 @@ describe("toEqual", function() {
jasmine.getEnv().requireFunctioningSets();
// Use 'duplicate' object in expected so sizes match
var actual = new Set();
var actual = new Set(); // eslint-disable-line compat/compat
actual.add({x: 1});
actual.add({x: 2});
var expected = new Set();
var expected = new Set(); // eslint-disable-line compat/compat
expected.add({x: 1});
expected.add({x: 1});
var message = 'Expected Set( Object({ x: 1 }), Object({ x: 2 }) ) to equal Set( Object({ x: 1 }), Object({ x: 1 }) ).';
@@ -533,9 +546,9 @@ describe("toEqual", function() {
jasmine.getEnv().requireFunctioningMaps();
// values are the same but with different object identity
var actual = new Map();
var actual = new Map(); // eslint-disable-line compat/compat
actual.set('a',{x:1});
var expected = new Map();
var expected = new Map(); // eslint-disable-line compat/compat
expected.set('a',{x:1});
expect(compareEquals(actual, expected).pass).toBe(true);
@@ -544,9 +557,9 @@ describe("toEqual", function() {
it("reports deep mismatches within Maps", function() {
jasmine.getEnv().requireFunctioningMaps();
var actual = new Map();
var actual = new Map(); // eslint-disable-line compat/compat
actual.set('a',{x:1});
var expected = new Map();
var expected = new Map(); // eslint-disable-line compat/compat
expected.set('a',{x:2});
var message = "Expected Map( [ 'a', Object({ x: 1 }) ] ) to equal Map( [ 'a', Object({ x: 2 }) ] ).";
@@ -556,9 +569,9 @@ describe("toEqual", function() {
it("reports mismatches between Maps nested in objects", function() {
jasmine.getEnv().requireFunctioningMaps();
var actual = {Maps:[new Map()]};
var actual = {Maps:[new Map()]}; // eslint-disable-line compat/compat
actual.Maps[0].set('a',1);
var expected = {Maps:[new Map()]};
var expected = {Maps:[new Map()]}; // eslint-disable-line compat/compat
expected.Maps[0].set('a',2);
var message = "Expected $.Maps[0] = Map( [ 'a', 1 ] ) to equal Map( [ 'a', 2 ] ).";
@@ -569,9 +582,9 @@ describe("toEqual", function() {
it("reports mismatches between Maps of different lengths", function() {
jasmine.getEnv().requireFunctioningMaps();
var actual = new Map();
var actual = new Map(); // eslint-disable-line compat/compat
actual.set('a',1);
var expected = new Map();
var expected = new Map(); // eslint-disable-line compat/compat
expected.set('a',2);
expected.set('b',1);
var message = "Expected Map( [ 'a', 1 ] ) to equal Map( [ 'a', 2 ], [ 'b', 1 ] ).";
@@ -582,9 +595,9 @@ describe("toEqual", function() {
it("reports mismatches between Maps with equal values but differing keys", function() {
jasmine.getEnv().requireFunctioningMaps();
var actual = new Map();
var actual = new Map(); // eslint-disable-line compat/compat
actual.set('a',1);
var expected = new Map();
var expected = new Map(); // eslint-disable-line compat/compat
expected.set('b',1);
var message = "Expected Map( [ 'a', 1 ] ) to equal Map( [ 'b', 1 ] ).";
@@ -594,9 +607,9 @@ describe("toEqual", function() {
it("does not report mismatches between Maps with keys with same object identity", function() {
jasmine.getEnv().requireFunctioningMaps();
var key = {x: 1};
var actual = new Map();
var actual = new Map(); // eslint-disable-line compat/compat
actual.set(key,2);
var expected = new Map();
var expected = new Map(); // eslint-disable-line compat/compat
expected.set(key,2);
expect(compareEquals(actual, expected).pass).toBe(true);
@@ -605,9 +618,9 @@ describe("toEqual", function() {
it("reports mismatches between Maps with identical keys with different object identity", function() {
jasmine.getEnv().requireFunctioningMaps();
var actual = new Map();
var actual = new Map(); // eslint-disable-line compat/compat
actual.set({x:1},2);
var expected = new Map();
var expected = new Map(); // eslint-disable-line compat/compat
expected.set({x:1},2);
var message = "Expected Map( [ Object({ x: 1 }), 2 ] ) to equal Map( [ Object({ x: 1 }), 2 ] ).";
@@ -617,9 +630,9 @@ describe("toEqual", function() {
it("does not report mismatches when comparing Map key to jasmine.anything()", function() {
jasmine.getEnv().requireFunctioningMaps();
var actual = new Map();
var actual = new Map(); // eslint-disable-line compat/compat
actual.set('a',1);
var expected = new Map();
var expected = new Map(); // eslint-disable-line compat/compat
expected.set(jasmineUnderTest.anything(),1);
expect(compareEquals(actual, expected).pass).toBe(true);
@@ -629,10 +642,10 @@ describe("toEqual", function() {
jasmine.getEnv().requireFunctioningMaps();
jasmine.getEnv().requireFunctioningSymbols();
var key = Symbol();
var actual = new Map();
var key = Symbol(); // eslint-disable-line compat/compat
var actual = new Map(); // eslint-disable-line compat/compat
actual.set(key,1);
var expected = new Map();
var expected = new Map(); // eslint-disable-line compat/compat
expected.set(key,1);
expect(compareEquals(actual, expected).pass).toBe(true);
@@ -642,10 +655,10 @@ describe("toEqual", function() {
jasmine.getEnv().requireFunctioningMaps();
jasmine.getEnv().requireFunctioningSymbols();
var actual = new Map();
actual.set(Symbol(),1);
var expected = new Map();
expected.set(Symbol(),1);
var actual = new Map(); // eslint-disable-line compat/compat
actual.set(Symbol(),1); // eslint-disable-line compat/compat
var expected = new Map(); // eslint-disable-line compat/compat
expected.set(Symbol(),1); // eslint-disable-line compat/compat
var message = "Expected Map( [ Symbol(), 1 ] ) to equal Map( [ Symbol(), 1 ] ).";
expect(compareEquals(actual, expected).message).toBe(message);
@@ -655,9 +668,9 @@ describe("toEqual", function() {
jasmine.getEnv().requireFunctioningMaps();
jasmine.getEnv().requireFunctioningSymbols();
var actual = new Map();
actual.set(Symbol(),1);
var expected = new Map();
var actual = new Map(); // eslint-disable-line compat/compat
actual.set(Symbol(),1); // eslint-disable-line compat/compat
var expected = new Map(); // eslint-disable-line compat/compat
expected.set(jasmineUnderTest.anything(),1);
expect(compareEquals(actual, expected).pass).toBe(true);

View File

@@ -0,0 +1,95 @@
describe("toHaveBeenCalledOnceWith", function () {
it("passes when the actual was called only once and with matching parameters", function () {
var pp = jasmineUnderTest.makePrettyPrinter(),
util = new jasmineUnderTest.MatchersUtil({ pp: pp }),
matcher = jasmineUnderTest.matchers.toHaveBeenCalledOnceWith(util),
calledSpy = new jasmineUnderTest.Spy('called-spy'),
result;
calledSpy('a', 'b');
result = matcher.compare(calledSpy, 'a', 'b');
expect(result.pass).toBe(true);
expect(result.message).toEqual("Expected spy called-spy to have been called 0 times, multiple times, or once, but with arguments different from:\n [ 'a', 'b' ]\nBut the actual call was:\n [ 'a', 'b' ].\n\n");
});
it("supports custom equality testers", function () {
var customEqualityTesters = [function() { return true; }],
matchersUtil = new jasmineUnderTest.MatchersUtil({customTesters: customEqualityTesters}),
matcher = jasmineUnderTest.matchers.toHaveBeenCalledOnceWith(matchersUtil),
calledSpy = new jasmineUnderTest.Spy('called-spy'),
result;
calledSpy('a', 'b');
result = matcher.compare(calledSpy, 'a', 'a');
expect(result.pass).toBe(true);
});
it("fails when the actual was never called", function () {
var pp = jasmineUnderTest.makePrettyPrinter(),
util = new jasmineUnderTest.MatchersUtil({ pp: pp }),
matcher = jasmineUnderTest.matchers.toHaveBeenCalledOnceWith(util),
calledSpy = new jasmineUnderTest.Spy('called-spy'),
result;
result = matcher.compare(calledSpy, 'a', 'b');
expect(result.pass).toBe(false);
expect(result.message).toEqual("Expected spy called-spy to have been called only once, and with given args:\n [ 'a', 'b' ]\nBut it was never called.\n\n");
});
it("fails when the actual was called once with different parameters", function () {
var pp = jasmineUnderTest.makePrettyPrinter(),
util = new jasmineUnderTest.MatchersUtil({ pp: pp }),
matcher = jasmineUnderTest.matchers.toHaveBeenCalledOnceWith(util),
calledSpy = new jasmineUnderTest.Spy('called-spy'),
result;
calledSpy('a', 'c');
result = matcher.compare(calledSpy, 'a', 'b');
expect(result.pass).toBe(false);
expect(result.message).toEqual("Expected spy called-spy to have been called only once, and with given args:\n [ 'a', 'b' ]\nBut the actual call was:\n [ 'a', 'c' ].\nExpected $[1] = 'c' to equal 'b'.\n\n");
});
it("fails when the actual was called multiple times with expected parameters", function () {
var pp = jasmineUnderTest.makePrettyPrinter(),
util = new jasmineUnderTest.MatchersUtil({ pp: pp }),
matcher = jasmineUnderTest.matchers.toHaveBeenCalledOnceWith(util),
calledSpy = new jasmineUnderTest.Spy('called-spy'),
result;
calledSpy('a', 'b');
calledSpy('a', 'b');
result = matcher.compare(calledSpy, 'a', 'b');
expect(result.pass).toBe(false);
expect(result.message).toEqual("Expected spy called-spy to have been called only once, and with given args:\n [ 'a', 'b' ]\nBut the actual calls were:\n [ 'a', 'b' ],\n [ 'a', 'b' ].\n\n");
});
it("fails when the actual was called multiple times (one of them - with expected parameters)", function () {
var pp = jasmineUnderTest.makePrettyPrinter(),
util = new jasmineUnderTest.MatchersUtil({ pp: pp }),
matcher = jasmineUnderTest.matchers.toHaveBeenCalledOnceWith(util),
calledSpy = new jasmineUnderTest.Spy('called-spy'),
result;
calledSpy('a', 'b');
calledSpy('a', 'c');
result = matcher.compare(calledSpy, 'a', 'b');
expect(result.pass).toBe(false);
expect(result.message).toEqual("Expected spy called-spy to have been called only once, and with given args:\n [ 'a', 'b' ]\nBut the actual calls were:\n [ 'a', 'b' ],\n [ 'a', 'c' ].\n\n");
});
it("throws an exception when the actual is not a spy", function () {
var pp = jasmineUnderTest.makePrettyPrinter(),
util = new jasmineUnderTest.MatchersUtil({ pp: pp }),
matcher = jasmineUnderTest.matchers.toHaveBeenCalledOnceWith(util),
fn = function () { };
expect(function () { matcher.compare(fn) }).toThrowError(/Expected a spy, but got Function./);
});
});

View File

@@ -0,0 +1,138 @@
/* eslint-disable compat/compat */
describe('toHaveSize', function() {
'use strict';
it('passes for an array whose length matches', function() {
var matcher = jasmineUnderTest.matchers.toHaveSize(),
result = matcher.compare([1, 2], 2);
expect(result.pass).toBe(true);
});
it('fails for an array whose length does not match', function() {
var matcher = jasmineUnderTest.matchers.toHaveSize(),
result = matcher.compare([1, 2, 3], 2);
expect(result.pass).toBe(false);
});
it('passes for an object with the proper number of keys', function() {
var matcher = jasmineUnderTest.matchers.toHaveSize(),
result = matcher.compare({a: 1, b: 2}, 2);
expect(result.pass).toBe(true);
});
it('fails for an object with a different number of keys', function() {
var matcher = jasmineUnderTest.matchers.toHaveSize(),
result = matcher.compare({a: 1, b: 2}, 1);
expect(result.pass).toBe(false);
});
it('passes for an object with an explicit `length` property that matches', function() {
var matcher = jasmineUnderTest.matchers.toHaveSize(),
result = matcher.compare({a: 1, b: 2, length: 5}, 5);
expect(result.pass).toBe(true);
});
it('fails for an object with an explicit `length` property that does not match', function() {
var matcher = jasmineUnderTest.matchers.toHaveSize(),
result = matcher.compare({a: 1, b: 2, length: 5}, 1);
expect(result.pass).toBe(false);
});
it('passes for a string whose length matches', function() {
var matcher = jasmineUnderTest.matchers.toHaveSize(),
result = matcher.compare('ab', 2);
expect(result.pass).toBe(true);
});
it('fails for a string whose length does not match', function() {
var matcher = jasmineUnderTest.matchers.toHaveSize(),
result = matcher.compare('abc', 2);
expect(result.pass).toBe(false);
});
it('passes for a Map whose length matches', function() {
jasmine.getEnv().requireFunctioningMaps();
var map = new Map();
map.set('a',1);
map.set('b',2);
var matcher = jasmineUnderTest.matchers.toHaveSize(),
result = matcher.compare(map, 2);
expect(result.pass).toBe(true);
});
it('fails for a Map whose length does not match', function() {
jasmine.getEnv().requireFunctioningMaps();
var map = new Map();
map.set('a',1);
map.set('b',2);
var matcher = jasmineUnderTest.matchers.toHaveSize(),
result = matcher.compare(map, 1);
expect(result.pass).toBe(false);
});
it('passes for a Set whose length matches', function() {
jasmine.getEnv().requireFunctioningSets();
var set = new Set();
set.add('a');
set.add('b');
var matcher = jasmineUnderTest.matchers.toHaveSize(),
result = matcher.compare(set, 2);
expect(result.pass).toBe(true);
});
it('fails for a Set whose length does not match', function() {
jasmine.getEnv().requireFunctioningSets();
var set = new Set();
set.add('a');
set.add('b');
var matcher = jasmineUnderTest.matchers.toHaveSize(),
result = matcher.compare(set, 1);
expect(result.pass).toBe(false);
});
it('throws an error for WeakSet', function() {
jasmine.getEnv().requireWeakSets();
var matcher = jasmineUnderTest.matchers.toHaveSize();
expect(function() {
matcher.compare(new WeakSet(), 2);
}).toThrowError('Cannot get size of [object WeakSet].');
});
it('throws an error for WeakMap', function() {
jasmine.getEnv().requireWeakMaps();
var matcher = jasmineUnderTest.matchers.toHaveSize();
expect(function() {
matcher.compare(new WeakMap(), 2);
}).toThrowError(/Cannot get size of \[object (WeakMap|Object)\]\./);
});
it('throws an error for DataView', function() {
var matcher = jasmineUnderTest.matchers.toHaveSize();
expect(function() {
matcher.compare(new DataView(new ArrayBuffer(128)), 2);
}).toThrowError(/Cannot get size of \[object (DataView|Object)\]\./);
});
});