Use const/let in specs, not var

This commit is contained in:
Steve Gravrock
2022-04-16 13:41:44 -07:00
parent 482dc883eb
commit 1166d10e43
111 changed files with 2522 additions and 2675 deletions

View File

@@ -1,73 +1,73 @@
describe('Any', function() {
it('matches a string', function() {
var any = new jasmineUnderTest.Any(String);
const any = new jasmineUnderTest.Any(String);
expect(any.asymmetricMatch('foo')).toBe(true);
});
it('matches a number', function() {
var any = new jasmineUnderTest.Any(Number);
const any = new jasmineUnderTest.Any(Number);
expect(any.asymmetricMatch(1)).toBe(true);
});
it('matches a function', function() {
var any = new jasmineUnderTest.Any(Function);
const any = new jasmineUnderTest.Any(Function);
expect(any.asymmetricMatch(function() {})).toBe(true);
});
it('matches an Object', function() {
var any = new jasmineUnderTest.Any(Object);
const any = new jasmineUnderTest.Any(Object);
expect(any.asymmetricMatch({})).toBe(true);
});
it('matches a Boolean', function() {
var any = new jasmineUnderTest.Any(Boolean);
const any = new jasmineUnderTest.Any(Boolean);
expect(any.asymmetricMatch(true)).toBe(true);
});
it('matches a Map', function() {
var any = new jasmineUnderTest.Any(Map);
const any = new jasmineUnderTest.Any(Map);
expect(any.asymmetricMatch(new Map())).toBe(true);
});
it('matches a Set', function() {
var any = new jasmineUnderTest.Any(Set);
const any = new jasmineUnderTest.Any(Set);
expect(any.asymmetricMatch(new Set())).toBe(true);
});
it('matches a TypedArray', function() {
var any = new jasmineUnderTest.Any(Uint32Array);
const any = new jasmineUnderTest.Any(Uint32Array);
expect(any.asymmetricMatch(new Uint32Array([]))).toBe(true);
});
it('matches a Symbol', function() {
var any = new jasmineUnderTest.Any(Symbol);
const any = new jasmineUnderTest.Any(Symbol);
expect(any.asymmetricMatch(Symbol())).toBe(true);
});
it('matches another constructed object', function() {
var Thing = function() {},
const Thing = function() {},
any = new jasmineUnderTest.Any(Thing);
expect(any.asymmetricMatch(new Thing())).toBe(true);
});
it('does not treat null as an Object', function() {
var any = new jasmineUnderTest.Any(Object);
const any = new jasmineUnderTest.Any(Object);
expect(any.asymmetricMatch(null)).toBe(false);
});
it("jasmineToString's itself", function() {
var any = new jasmineUnderTest.Any(Number);
const any = new jasmineUnderTest.Any(Number);
expect(any.jasmineToString()).toEqual('<jasmine.any(Number)>');
expect(any.jasmineToString()).toEqual('<jasmine.any(Number)>');

View File

@@ -1,67 +1,67 @@
describe('Anything', function() {
it('matches a string', function() {
var anything = new jasmineUnderTest.Anything();
const anything = new jasmineUnderTest.Anything();
expect(anything.asymmetricMatch('foo')).toBe(true);
});
it('matches a number', function() {
var anything = new jasmineUnderTest.Anything();
const anything = new jasmineUnderTest.Anything();
expect(anything.asymmetricMatch(42)).toBe(true);
});
it('matches an object', function() {
var anything = new jasmineUnderTest.Anything();
const anything = new jasmineUnderTest.Anything();
expect(anything.asymmetricMatch({ foo: 'bar' })).toBe(true);
});
it('matches an array', function() {
var anything = new jasmineUnderTest.Anything();
const anything = new jasmineUnderTest.Anything();
expect(anything.asymmetricMatch([1, 2, 3])).toBe(true);
});
it('matches a Map', function() {
var anything = new jasmineUnderTest.Anything();
const anything = new jasmineUnderTest.Anything();
expect(anything.asymmetricMatch(new Map())).toBe(true);
});
it('matches a Set', function() {
var anything = new jasmineUnderTest.Anything();
const anything = new jasmineUnderTest.Anything();
expect(anything.asymmetricMatch(new Set())).toBe(true);
});
it('matches a TypedArray', function() {
var anything = new jasmineUnderTest.Anything();
const anything = new jasmineUnderTest.Anything();
expect(anything.asymmetricMatch(new Uint32Array([]))).toBe(true);
});
it('matches a Symbol', function() {
var anything = new jasmineUnderTest.Anything();
const anything = new jasmineUnderTest.Anything();
expect(anything.asymmetricMatch(Symbol())).toBe(true);
});
it("doesn't match undefined", function() {
var anything = new jasmineUnderTest.Anything();
const anything = new jasmineUnderTest.Anything();
expect(anything.asymmetricMatch()).toBe(false);
expect(anything.asymmetricMatch(undefined)).toBe(false);
});
it("doesn't match null", function() {
var anything = new jasmineUnderTest.Anything();
const anything = new jasmineUnderTest.Anything();
expect(anything.asymmetricMatch(null)).toBe(false);
});
it("jasmineToString's itself", function() {
var anything = new jasmineUnderTest.Anything();
const anything = new jasmineUnderTest.Anything();
expect(anything.jasmineToString()).toEqual('<jasmine.anything>');
});

View File

@@ -1,12 +1,12 @@
describe('ArrayContaining', function() {
it('matches any actual to an empty array', function() {
var containing = new jasmineUnderTest.ArrayContaining([]);
const containing = new jasmineUnderTest.ArrayContaining([]);
expect(containing.asymmetricMatch('foo')).toBe(true);
});
it('does not work when not passed an array', function() {
var containing = new jasmineUnderTest.ArrayContaining('foo');
const containing = new jasmineUnderTest.ArrayContaining('foo');
expect(function() {
containing.asymmetricMatch([]);
@@ -14,35 +14,35 @@ describe('ArrayContaining', function() {
});
it('matches when the item is in the actual', function() {
var containing = new jasmineUnderTest.ArrayContaining(['foo']);
var matchersUtil = new jasmineUnderTest.MatchersUtil();
const containing = new jasmineUnderTest.ArrayContaining(['foo']);
const matchersUtil = new jasmineUnderTest.MatchersUtil();
expect(containing.asymmetricMatch(['foo'], matchersUtil)).toBe(true);
});
it('matches when additional items are in the actual', function() {
var containing = new jasmineUnderTest.ArrayContaining(['foo']);
var matchersUtil = new jasmineUnderTest.MatchersUtil();
const containing = new jasmineUnderTest.ArrayContaining(['foo']);
const matchersUtil = new jasmineUnderTest.MatchersUtil();
expect(containing.asymmetricMatch(['foo', 'bar'], matchersUtil)).toBe(true);
});
it('does not match when the item is not in the actual', function() {
var containing = new jasmineUnderTest.ArrayContaining(['foo']);
var matchersUtil = new jasmineUnderTest.MatchersUtil();
const containing = new jasmineUnderTest.ArrayContaining(['foo']);
const matchersUtil = new jasmineUnderTest.MatchersUtil();
expect(containing.asymmetricMatch(['bar'], matchersUtil)).toBe(false);
});
it('does not match when the actual is not an array', function() {
var containing = new jasmineUnderTest.ArrayContaining(['foo']);
var matchersUtil = new jasmineUnderTest.MatchersUtil();
const containing = new jasmineUnderTest.ArrayContaining(['foo']);
const matchersUtil = new jasmineUnderTest.MatchersUtil();
expect(containing.asymmetricMatch('foo', matchersUtil)).toBe(false);
});
it('jasmineToStrings itself', function() {
var sample = [],
const sample = [],
matcher = new jasmineUnderTest.ArrayContaining(sample),
pp = jasmine.createSpy('pp').and.returnValue('sample');
@@ -53,7 +53,7 @@ describe('ArrayContaining', function() {
});
it('uses custom equality testers', function() {
var tester = function(a, b) {
const tester = function(a, b) {
// All "foo*" strings match each other.
if (
typeof a == 'string' &&
@@ -64,8 +64,8 @@ describe('ArrayContaining', function() {
return true;
}
};
var containing = new jasmineUnderTest.ArrayContaining(['fooVal']);
var matchersUtil = new jasmineUnderTest.MatchersUtil({
const containing = new jasmineUnderTest.ArrayContaining(['fooVal']);
const matchersUtil = new jasmineUnderTest.MatchersUtil({
customTesters: [tester]
});

View File

@@ -1,13 +1,13 @@
describe('ArrayWithExactContents', function() {
it('matches an array with the same items in a different order', function() {
var matcher = new jasmineUnderTest.ArrayWithExactContents(['a', 2, /a/]);
var matchersUtil = new jasmineUnderTest.MatchersUtil();
const matcher = new jasmineUnderTest.ArrayWithExactContents(['a', 2, /a/]);
const matchersUtil = new jasmineUnderTest.MatchersUtil();
expect(matcher.asymmetricMatch([2, 'a', /a/], matchersUtil)).toBe(true);
});
it('does not work when not passed an array', function() {
var matcher = new jasmineUnderTest.ArrayWithExactContents('foo');
const matcher = new jasmineUnderTest.ArrayWithExactContents('foo');
expect(function() {
matcher.asymmetricMatch([]);
@@ -15,8 +15,8 @@ describe('ArrayWithExactContents', function() {
});
it('does not match when an item is missing', function() {
var matcher = new jasmineUnderTest.ArrayWithExactContents(['a', 2, /a/]);
var matchersUtil = new jasmineUnderTest.MatchersUtil();
const matcher = new jasmineUnderTest.ArrayWithExactContents(['a', 2, /a/]);
const matchersUtil = new jasmineUnderTest.MatchersUtil();
expect(matcher.asymmetricMatch(['a', 2], matchersUtil)).toBe(false);
expect(matcher.asymmetricMatch(['a', 2, undefined], matchersUtil)).toBe(
@@ -25,14 +25,14 @@ describe('ArrayWithExactContents', function() {
});
it('does not match when there is an extra item', function() {
var matcher = new jasmineUnderTest.ArrayWithExactContents(['a']);
var matchersUtil = new jasmineUnderTest.MatchersUtil();
const matcher = new jasmineUnderTest.ArrayWithExactContents(['a']);
const matchersUtil = new jasmineUnderTest.MatchersUtil();
expect(matcher.asymmetricMatch(['a', 2], matchersUtil)).toBe(false);
});
it('jasmineToStrings itself', function() {
var sample = [],
const sample = [],
matcher = new jasmineUnderTest.ArrayWithExactContents(sample),
pp = jasmine.createSpy('pp').and.returnValue('sample');
@@ -43,7 +43,7 @@ describe('ArrayWithExactContents', function() {
});
it('uses custom equality testers', function() {
var tester = function(a, b) {
const tester = function(a, b) {
// All "foo*" strings match each other.
if (
typeof a == 'string' &&
@@ -54,8 +54,8 @@ describe('ArrayWithExactContents', function() {
return true;
}
};
var matcher = new jasmineUnderTest.ArrayWithExactContents(['fooVal']);
var matchersUtil = new jasmineUnderTest.MatchersUtil({
const matcher = new jasmineUnderTest.ArrayWithExactContents(['fooVal']);
const matchersUtil = new jasmineUnderTest.MatchersUtil({
customTesters: [tester]
});

View File

@@ -1,20 +1,20 @@
describe('Empty', function() {
it('matches an empty object', function() {
var empty = new jasmineUnderTest.Empty();
const empty = new jasmineUnderTest.Empty();
expect(empty.asymmetricMatch({})).toBe(true);
expect(empty.asymmetricMatch({ undefined: false })).toBe(false);
});
it('matches an empty array', function() {
var empty = new jasmineUnderTest.Empty();
const empty = new jasmineUnderTest.Empty();
expect(empty.asymmetricMatch([])).toBe(true);
expect(empty.asymmetricMatch([1, 12, 3])).toBe(false);
});
it('matches an empty string', function() {
var empty = new jasmineUnderTest.Empty();
const empty = new jasmineUnderTest.Empty();
expect(empty.asymmetricMatch('')).toBe(true);
expect(empty.asymmetricMatch('')).toBe(true);
@@ -22,8 +22,8 @@ describe('Empty', function() {
});
it('matches an empty map', function() {
var empty = new jasmineUnderTest.Empty();
var fullMap = new Map();
const empty = new jasmineUnderTest.Empty();
const fullMap = new Map();
fullMap.set('thing', 2);
expect(empty.asymmetricMatch(new Map())).toBe(true);
@@ -31,8 +31,8 @@ describe('Empty', function() {
});
it('matches an empty set', function() {
var empty = new jasmineUnderTest.Empty();
var fullSet = new Set();
const empty = new jasmineUnderTest.Empty();
const fullSet = new Set();
fullSet.add(3);
expect(empty.asymmetricMatch(new Set())).toBe(true);
@@ -40,7 +40,7 @@ describe('Empty', function() {
});
it('matches an empty typed array', function() {
var empty = new jasmineUnderTest.Empty();
const empty = new jasmineUnderTest.Empty();
expect(empty.asymmetricMatch(new Int16Array())).toBe(true);
expect(empty.asymmetricMatch(new Int16Array([1, 2]))).toBe(false);

View File

@@ -1,6 +1,6 @@
describe('Falsy', function() {
it('is true for an empty string', function() {
var falsy = new jasmineUnderTest.Falsy();
const falsy = new jasmineUnderTest.Falsy();
expect(falsy.asymmetricMatch('')).toBe(true);
expect(falsy.asymmetricMatch('')).toBe(true);
@@ -8,7 +8,7 @@ describe('Falsy', function() {
});
it('is false for a number that is 0', function() {
var falsy = new jasmineUnderTest.Falsy(Number);
const falsy = new jasmineUnderTest.Falsy(Number);
expect(falsy.asymmetricMatch(1)).toBe(false);
expect(falsy.asymmetricMatch(0)).toBe(true);
@@ -17,20 +17,20 @@ describe('Falsy', function() {
});
it('is true for a null or undefined', function() {
var falsy = new jasmineUnderTest.Falsy(Function);
const falsy = new jasmineUnderTest.Falsy(Function);
expect(falsy.asymmetricMatch(null)).toBe(true);
expect(falsy.asymmetricMatch(undefined)).toBe(true);
});
it('is true for NaN', function() {
var falsy = new jasmineUnderTest.Falsy(Object);
const falsy = new jasmineUnderTest.Falsy(Object);
expect(falsy.asymmetricMatch(NaN)).toBe(true);
});
it('is true for a false Boolean', function() {
var falsy = new jasmineUnderTest.Falsy(Boolean);
const falsy = new jasmineUnderTest.Falsy(Boolean);
expect(falsy.asymmetricMatch(false)).toBe(true);
expect(falsy.asymmetricMatch(true)).toBe(false);

View File

@@ -1,104 +1,110 @@
describe('MapContaining', function() {
it('matches any actual map to an empty map', function() {
var actualMap = new Map([['foo', 'bar']]);
var containing = new jasmineUnderTest.MapContaining(new Map());
const actualMap = new Map([['foo', 'bar']]);
const containing = new jasmineUnderTest.MapContaining(new Map());
expect(containing.asymmetricMatch(actualMap)).toBe(true);
});
it('matches when all the key/value pairs in sample have matches in actual', function() {
var actualMap = new Map([
const actualMap = new Map([
['foo', [1, 2, 3]],
[{ foo: 'bar' }, 'baz'],
['other', 'any']
]);
var containingMap = new Map([[{ foo: 'bar' }, 'baz'], ['foo', [1, 2, 3]]]);
var containing = new jasmineUnderTest.MapContaining(containingMap);
var matchersUtil = new jasmineUnderTest.MatchersUtil();
const containingMap = new Map([
[{ foo: 'bar' }, 'baz'],
['foo', [1, 2, 3]]
]);
const containing = new jasmineUnderTest.MapContaining(containingMap);
const matchersUtil = new jasmineUnderTest.MatchersUtil();
expect(containing.asymmetricMatch(actualMap, matchersUtil)).toBe(true);
});
it('does not match when a key is not in actual', function() {
var actualMap = new Map([
const actualMap = new Map([
['foo', [1, 2, 3]],
[{ foo: 'not a bar' }, 'baz']
]);
var containingMap = new Map([[{ foo: 'bar' }, 'baz'], ['foo', [1, 2, 3]]]);
var containing = new jasmineUnderTest.MapContaining(containingMap);
var matchersUtil = new jasmineUnderTest.MatchersUtil();
const containingMap = new Map([
[{ foo: 'bar' }, 'baz'],
['foo', [1, 2, 3]]
]);
const containing = new jasmineUnderTest.MapContaining(containingMap);
const matchersUtil = new jasmineUnderTest.MatchersUtil();
expect(containing.asymmetricMatch(actualMap, matchersUtil)).toBe(false);
});
it('does not match when a value is not in actual', function() {
var actualMap = new Map([['foo', [1, 2, 3]], [{ foo: 'bar' }, 'baz']]);
const actualMap = new Map([['foo', [1, 2, 3]], [{ foo: 'bar' }, 'baz']]);
var containingMap = new Map([[{ foo: 'bar' }, 'baz'], ['foo', [1, 2]]]);
var containing = new jasmineUnderTest.MapContaining(containingMap);
var matchersUtil = new jasmineUnderTest.MatchersUtil();
const containingMap = new Map([[{ foo: 'bar' }, 'baz'], ['foo', [1, 2]]]);
const containing = new jasmineUnderTest.MapContaining(containingMap);
const matchersUtil = new jasmineUnderTest.MatchersUtil();
expect(containing.asymmetricMatch(actualMap, matchersUtil)).toBe(false);
});
it('matches when all the key/value pairs in sample have asymmetric matches in actual', function() {
var actualMap = new Map([
const actualMap = new Map([
['foo1', 'not a bar'],
['foo2', 'bar'],
['baz', [1, 2, 3, 4]]
]);
var containingMap = new Map([
const containingMap = new Map([
[jasmineUnderTest.stringMatching(/^foo\d/), 'bar'],
['baz', jasmineUnderTest.arrayContaining([2, 3])]
]);
var containing = new jasmineUnderTest.MapContaining(containingMap);
var matchersUtil = new jasmineUnderTest.MatchersUtil();
const containing = new jasmineUnderTest.MapContaining(containingMap);
const matchersUtil = new jasmineUnderTest.MatchersUtil();
expect(containing.asymmetricMatch(actualMap, matchersUtil)).toBe(true);
});
it('does not match when a key in sample has no asymmetric matches in actual', function() {
var actualMap = new Map([['a-foo1', 'bar'], ['baz', [1, 2, 3, 4]]]);
const actualMap = new Map([['a-foo1', 'bar'], ['baz', [1, 2, 3, 4]]]);
var containingMap = new Map([
const containingMap = new Map([
[jasmineUnderTest.stringMatching(/^foo\d/), 'bar'],
['baz', jasmineUnderTest.arrayContaining([2, 3])]
]);
var containing = new jasmineUnderTest.MapContaining(containingMap);
var matchersUtil = new jasmineUnderTest.MatchersUtil();
const containing = new jasmineUnderTest.MapContaining(containingMap);
const matchersUtil = new jasmineUnderTest.MatchersUtil();
expect(containing.asymmetricMatch(actualMap, matchersUtil)).toBe(false);
});
it('does not match when a value in sample has no asymmetric matches in actual', function() {
var actualMap = new Map([['foo1', 'bar'], ['baz', [1, 2, 3, 4]]]);
const actualMap = new Map([['foo1', 'bar'], ['baz', [1, 2, 3, 4]]]);
var containingMap = new Map([
const containingMap = new Map([
[jasmineUnderTest.stringMatching(/^foo\d/), 'bar'],
['baz', jasmineUnderTest.arrayContaining([4, 5])]
]);
var containing = new jasmineUnderTest.MapContaining(containingMap);
var matchersUtil = new jasmineUnderTest.MatchersUtil();
const containing = new jasmineUnderTest.MapContaining(containingMap);
const matchersUtil = new jasmineUnderTest.MatchersUtil();
expect(containing.asymmetricMatch(actualMap, matchersUtil)).toBe(false);
});
it('matches recursively', function() {
var actualMap = new Map([
const actualMap = new Map([
['foo', new Map([['foo1', 1], ['foo2', 2]])],
[new Map([[1, 'bar1'], [2, 'bar2']]), 'bar'],
['other', 'any']
]);
var containingMap = new Map([
const containingMap = new Map([
['foo', new jasmineUnderTest.MapContaining(new Map([['foo1', 1]]))],
[new jasmineUnderTest.MapContaining(new Map([[2, 'bar2']])), 'bar']
]);
var containing = new jasmineUnderTest.MapContaining(containingMap);
var matchersUtil = new jasmineUnderTest.MatchersUtil();
const containing = new jasmineUnderTest.MapContaining(containingMap);
const matchersUtil = new jasmineUnderTest.MatchersUtil();
expect(containing.asymmetricMatch(actualMap, matchersUtil)).toBe(true);
});
@@ -110,9 +116,11 @@ describe('MapContaining', function() {
? a < 0 && b < 0
: a === b;
}
var actualMap = new Map([['foo', -1]]);
var containing = new jasmineUnderTest.MapContaining(new Map([['foo', -2]]));
var matchersUtil = new jasmineUnderTest.MatchersUtil({
const actualMap = new Map([['foo', -1]]);
const containing = new jasmineUnderTest.MapContaining(
new Map([['foo', -2]])
);
const matchersUtil = new jasmineUnderTest.MatchersUtil({
customTesters: [tester]
});
@@ -120,7 +128,7 @@ describe('MapContaining', function() {
});
it('does not match when actual is not a map', function() {
var containingMap = new Map([['foo', 'bar']]);
const containingMap = new Map([['foo', 'bar']]);
expect(
new jasmineUnderTest.MapContaining(containingMap).asymmetricMatch('foo')
).toBe(false);
@@ -143,7 +151,7 @@ describe('MapContaining', function() {
});
it('defines a `jasmineToString` method', function() {
var sample = new Map(),
const sample = new Map(),
containing = new jasmineUnderTest.MapContaining(sample),
pp = jasmine.createSpy('pp').and.returnValue('sample');

View File

@@ -1,20 +1,20 @@
describe('NotEmpty', function() {
it('matches a non empty object', function() {
var notEmpty = new jasmineUnderTest.NotEmpty();
const notEmpty = new jasmineUnderTest.NotEmpty();
expect(notEmpty.asymmetricMatch({ undefined: false })).toBe(true);
expect(notEmpty.asymmetricMatch({})).toBe(false);
});
it('matches a non empty array', function() {
var notEmpty = new jasmineUnderTest.NotEmpty();
const notEmpty = new jasmineUnderTest.NotEmpty();
expect(notEmpty.asymmetricMatch([1, 12, 3])).toBe(true);
expect(notEmpty.asymmetricMatch([])).toBe(false);
});
it('matches a non empty string', function() {
var notEmpty = new jasmineUnderTest.NotEmpty();
const notEmpty = new jasmineUnderTest.NotEmpty();
expect(notEmpty.asymmetricMatch('12312')).toBe(true);
expect(notEmpty.asymmetricMatch('')).toBe(false);
@@ -22,27 +22,27 @@ describe('NotEmpty', function() {
});
it('matches a non empty map', function() {
var notEmpty = new jasmineUnderTest.NotEmpty();
var fullMap = new Map();
const notEmpty = new jasmineUnderTest.NotEmpty();
const fullMap = new Map();
fullMap.set('one', 1);
var emptyMap = new Map();
const emptyMap = new Map();
expect(notEmpty.asymmetricMatch(fullMap)).toBe(true);
expect(notEmpty.asymmetricMatch(emptyMap)).toBe(false);
});
it('matches a non empty set', function() {
var notEmpty = new jasmineUnderTest.NotEmpty();
var filledSet = new Set();
const notEmpty = new jasmineUnderTest.NotEmpty();
const filledSet = new Set();
filledSet.add(1);
var emptySet = new Set();
const emptySet = new Set();
expect(notEmpty.asymmetricMatch(filledSet)).toBe(true);
expect(notEmpty.asymmetricMatch(emptySet)).toBe(false);
});
it('matches a non empty typed array', function() {
var notEmpty = new jasmineUnderTest.NotEmpty();
const notEmpty = new jasmineUnderTest.NotEmpty();
expect(notEmpty.asymmetricMatch(new Int16Array([1, 2, 3]))).toBe(true);
expect(notEmpty.asymmetricMatch(new Int16Array())).toBe(false);

View File

@@ -1,13 +1,13 @@
describe('ObjectContaining', function() {
it('matches any object actual to an empty object', function() {
var containing = new jasmineUnderTest.ObjectContaining({});
var matchersUtil = new jasmineUnderTest.MatchersUtil();
const containing = new jasmineUnderTest.ObjectContaining({});
const matchersUtil = new jasmineUnderTest.MatchersUtil();
expect(containing.asymmetricMatch({ foo: 1 }, matchersUtil)).toBe(true);
});
it('does not match when the actual is not an object', function() {
var containing = new jasmineUnderTest.ObjectContaining({});
const containing = new jasmineUnderTest.ObjectContaining({});
[1, true, undefined, 'a string'].forEach(function(actual) {
expect(containing.asymmetricMatch(actual)).toBe(false);
@@ -15,7 +15,7 @@ describe('ObjectContaining', function() {
});
it('does not match an empty object actual', function() {
var containing = new jasmineUnderTest.ObjectContaining('foo');
const containing = new jasmineUnderTest.ObjectContaining('foo');
expect(function() {
containing.asymmetricMatch({});
@@ -23,8 +23,8 @@ describe('ObjectContaining', function() {
});
it('matches when the key/value pair is present in the actual', function() {
var containing = new jasmineUnderTest.ObjectContaining({ foo: 'fooVal' });
var matchersUtil = new jasmineUnderTest.MatchersUtil();
const containing = new jasmineUnderTest.ObjectContaining({ foo: 'fooVal' });
const matchersUtil = new jasmineUnderTest.MatchersUtil();
expect(
containing.asymmetricMatch({ foo: 'fooVal', bar: 'barVal' }, matchersUtil)
@@ -32,8 +32,8 @@ describe('ObjectContaining', function() {
});
it('does not match when the key/value pair is not present in the actual', function() {
var containing = new jasmineUnderTest.ObjectContaining({ foo: 'fooVal' });
var matchersUtil = new jasmineUnderTest.MatchersUtil();
const containing = new jasmineUnderTest.ObjectContaining({ foo: 'fooVal' });
const matchersUtil = new jasmineUnderTest.MatchersUtil();
expect(
containing.asymmetricMatch(
@@ -44,8 +44,8 @@ describe('ObjectContaining', function() {
});
it('does not match when the key is present but the value is different in the actual', function() {
var containing = new jasmineUnderTest.ObjectContaining({ foo: 'other' });
var matchersUtil = new jasmineUnderTest.MatchersUtil();
const containing = new jasmineUnderTest.ObjectContaining({ foo: 'other' });
const matchersUtil = new jasmineUnderTest.MatchersUtil();
expect(
containing.asymmetricMatch({ foo: 'fooVal', bar: 'barVal' }, matchersUtil)
@@ -53,7 +53,7 @@ describe('ObjectContaining', function() {
});
it("jasmineToString's itself", function() {
var sample = {},
const sample = {},
matcher = new jasmineUnderTest.ObjectContaining(sample),
pp = jasmine.createSpy('pp').and.returnValue('sample');
@@ -64,10 +64,10 @@ describe('ObjectContaining', function() {
});
it('matches recursively', function() {
var containing = new jasmineUnderTest.ObjectContaining({
const containing = new jasmineUnderTest.ObjectContaining({
one: new jasmineUnderTest.ObjectContaining({ two: {} })
});
var matchersUtil = new jasmineUnderTest.MatchersUtil();
const matchersUtil = new jasmineUnderTest.MatchersUtil();
expect(containing.asymmetricMatch({ one: { two: {} } }, matchersUtil)).toBe(
true
@@ -75,8 +75,10 @@ describe('ObjectContaining', function() {
});
it('matches when key is present with undefined value', function() {
var containing = new jasmineUnderTest.ObjectContaining({ one: undefined });
var matchersUtil = new jasmineUnderTest.MatchersUtil();
const containing = new jasmineUnderTest.ObjectContaining({
one: undefined
});
const matchersUtil = new jasmineUnderTest.MatchersUtil();
expect(containing.asymmetricMatch({ one: undefined }, matchersUtil)).toBe(
true
@@ -84,17 +86,19 @@ describe('ObjectContaining', function() {
});
it('does not match when key with undefined value is not present', function() {
var containing = new jasmineUnderTest.ObjectContaining({ one: undefined });
var matchersUtil = new jasmineUnderTest.MatchersUtil();
const containing = new jasmineUnderTest.ObjectContaining({
one: undefined
});
const matchersUtil = new jasmineUnderTest.MatchersUtil();
expect(containing.asymmetricMatch({}, matchersUtil)).toBe(false);
});
it('matches defined properties', function() {
var containing = new jasmineUnderTest.ObjectContaining({ foo: 'fooVal' });
var matchersUtil = new jasmineUnderTest.MatchersUtil();
const containing = new jasmineUnderTest.ObjectContaining({ foo: 'fooVal' });
const matchersUtil = new jasmineUnderTest.MatchersUtil();
var definedPropertyObject = {};
const definedPropertyObject = {};
Object.defineProperty(definedPropertyObject, 'foo', {
get: function() {
return 'fooVal';
@@ -106,17 +110,17 @@ describe('ObjectContaining', function() {
});
it('matches prototype properties', function() {
var containing = new jasmineUnderTest.ObjectContaining({ foo: 'fooVal' });
var matchersUtil = new jasmineUnderTest.MatchersUtil();
const containing = new jasmineUnderTest.ObjectContaining({ foo: 'fooVal' });
const matchersUtil = new jasmineUnderTest.MatchersUtil();
var prototypeObject = { foo: 'fooVal' };
var obj = Object.create(prototypeObject);
const prototypeObject = { foo: 'fooVal' };
const obj = Object.create(prototypeObject);
expect(containing.asymmetricMatch(obj, matchersUtil)).toBe(true);
});
it('uses custom equality testers', function() {
var tester = function(a, b) {
const tester = function(a, b) {
// All "foo*" strings match each other.
if (
typeof a == 'string' &&
@@ -127,8 +131,8 @@ describe('ObjectContaining', function() {
return true;
}
};
var containing = new jasmineUnderTest.ObjectContaining({ foo: 'fooVal' });
var matchersUtil = new jasmineUnderTest.MatchersUtil({
const containing = new jasmineUnderTest.ObjectContaining({ foo: 'fooVal' });
const matchersUtil = new jasmineUnderTest.MatchersUtil({
customTesters: [tester]
});
@@ -140,7 +144,7 @@ describe('ObjectContaining', function() {
describe('valuesForDiff_', function() {
describe('when other is not an object', function() {
it('sets self to jasmineToString()', function() {
var containing = new jasmineUnderTest.ObjectContaining({}),
const containing = new jasmineUnderTest.ObjectContaining({}),
pp = jasmineUnderTest.makePrettyPrinter(),
result = containing.valuesForDiff_('a', pp);
@@ -153,7 +157,7 @@ describe('ObjectContaining', function() {
describe('when other is an object', function() {
it('includes keys that are present in both other and sample', function() {
var sample = { a: 1, b: 2 },
const sample = { a: 1, b: 2 },
other = { a: 3, b: 4 },
containing = new jasmineUnderTest.ObjectContaining(sample),
result = containing.valuesForDiff_(other);
@@ -168,7 +172,7 @@ describe('ObjectContaining', function() {
});
it('includes keys that are present only in sample', function() {
var sample = { a: 1, b: 2 },
const sample = { a: 1, b: 2 },
other = { a: 3 },
containing = new jasmineUnderTest.ObjectContaining(sample),
result = containing.valuesForDiff_(other);
@@ -186,7 +190,7 @@ describe('ObjectContaining', function() {
});
it('omits keys that are present only in other', function() {
var sample = { a: 1, b: 2 },
const sample = { a: 1, b: 2 },
other = { a: 3, b: 4, c: 5 },
containing = new jasmineUnderTest.ObjectContaining(sample),
result = containing.valuesForDiff_(other);

View File

@@ -1,66 +1,66 @@
describe('SetContaining', function() {
it('matches any actual set to an empty set', function() {
var actualSet = new Set(['foo', 'bar']);
var containing = new jasmineUnderTest.SetContaining(new Set());
const actualSet = new Set(['foo', 'bar']);
const containing = new jasmineUnderTest.SetContaining(new Set());
expect(containing.asymmetricMatch(actualSet)).toBe(true);
});
it('matches when all the values in sample have matches in actual', function() {
var actualSet = new Set([{ foo: 'bar' }, 'baz', [1, 2, 3]]);
const actualSet = new Set([{ foo: 'bar' }, 'baz', [1, 2, 3]]);
var containingSet = new Set([[1, 2, 3], { foo: 'bar' }]);
var containing = new jasmineUnderTest.SetContaining(containingSet);
var matchersUtil = new jasmineUnderTest.MatchersUtil();
const containingSet = new Set([[1, 2, 3], { foo: 'bar' }]);
const containing = new jasmineUnderTest.SetContaining(containingSet);
const matchersUtil = new jasmineUnderTest.MatchersUtil();
expect(containing.asymmetricMatch(actualSet, matchersUtil)).toBe(true);
});
it('does not match when a value is not in actual', function() {
var actualSet = new Set([{ foo: 'bar' }, 'baz', [1, 2, 3]]);
const actualSet = new Set([{ foo: 'bar' }, 'baz', [1, 2, 3]]);
var containingSet = new Set([[1, 2], { foo: 'bar' }]);
var containing = new jasmineUnderTest.SetContaining(containingSet);
var matchersUtil = new jasmineUnderTest.MatchersUtil();
const containingSet = new Set([[1, 2], { foo: 'bar' }]);
const containing = new jasmineUnderTest.SetContaining(containingSet);
const matchersUtil = new jasmineUnderTest.MatchersUtil();
expect(containing.asymmetricMatch(actualSet, matchersUtil)).toBe(false);
});
it('matches when all the values in sample have asymmetric matches in actual', function() {
var actualSet = new Set([[1, 2, 3, 4], 'other', 'foo1']);
const actualSet = new Set([[1, 2, 3, 4], 'other', 'foo1']);
var containingSet = new Set([
const containingSet = new Set([
jasmineUnderTest.stringMatching(/^foo\d/),
jasmineUnderTest.arrayContaining([2, 3])
]);
var containing = new jasmineUnderTest.SetContaining(containingSet);
var matchersUtil = new jasmineUnderTest.MatchersUtil();
const containing = new jasmineUnderTest.SetContaining(containingSet);
const matchersUtil = new jasmineUnderTest.MatchersUtil();
expect(containing.asymmetricMatch(actualSet, matchersUtil)).toBe(true);
});
it('does not match when a value in sample has no asymmetric matches in actual', function() {
var actualSet = new Set(['a-foo1', [1, 2, 3, 4], 'other']);
const actualSet = new Set(['a-foo1', [1, 2, 3, 4], 'other']);
var containingSet = new Set([
const containingSet = new Set([
jasmine.stringMatching(/^foo\d/),
jasmine.arrayContaining([2, 3])
]);
var containing = new jasmineUnderTest.SetContaining(containingSet);
var matchersUtil = new jasmineUnderTest.MatchersUtil();
const containing = new jasmineUnderTest.SetContaining(containingSet);
const matchersUtil = new jasmineUnderTest.MatchersUtil();
expect(containing.asymmetricMatch(actualSet, matchersUtil)).toBe(false);
});
it('matches recursively', function() {
var actualSet = new Set(['foo', new Set([1, 'bar', 2]), 'other']);
const actualSet = new Set(['foo', new Set([1, 'bar', 2]), 'other']);
var containingSet = new Set([
const containingSet = new Set([
new jasmineUnderTest.SetContaining(new Set(['bar'])),
'foo'
]);
var containing = new jasmineUnderTest.SetContaining(containingSet);
var matchersUtil = new jasmineUnderTest.MatchersUtil();
const containing = new jasmineUnderTest.SetContaining(containingSet);
const matchersUtil = new jasmineUnderTest.MatchersUtil();
expect(containing.asymmetricMatch(actualSet, matchersUtil)).toBe(true);
});
@@ -72,9 +72,9 @@ describe('SetContaining', function() {
? a < 0 && b < 0
: a === b;
}
var actualSet = new Set(['foo', -1]);
var containing = new jasmineUnderTest.SetContaining(new Set([-2, 'foo']));
var matchersUtil = new jasmineUnderTest.MatchersUtil({
const actualSet = new Set(['foo', -1]);
const containing = new jasmineUnderTest.SetContaining(new Set([-2, 'foo']));
const matchersUtil = new jasmineUnderTest.MatchersUtil({
customTesters: [tester]
});
@@ -82,7 +82,7 @@ describe('SetContaining', function() {
});
it('does not match when actual is not a set', function() {
var containingSet = new Set(['foo']);
const containingSet = new Set(['foo']);
expect(
new jasmineUnderTest.SetContaining(containingSet).asymmetricMatch('foo')
).toBe(false);
@@ -103,7 +103,7 @@ describe('SetContaining', function() {
});
it('defines a `jasmineToString` method', function() {
var sample = new Set(),
const sample = new Set(),
containing = new jasmineUnderTest.SetContaining(sample),
pp = jasmine.createSpy('pp').and.returnValue('sample');

View File

@@ -1,6 +1,6 @@
describe('StringContaining', function() {
it('searches for a provided substring when the expected is a String', function() {
var matcher = new jasmineUnderTest.StringContaining('foo');
const matcher = new jasmineUnderTest.StringContaining('foo');
expect(matcher.asymmetricMatch('barfoobaz')).toBe(true);
expect(matcher.asymmetricMatch('barbaz')).toBe(false);
@@ -13,12 +13,12 @@ describe('StringContaining', function() {
});
it('fails when the actual is not a String', function() {
var matcher = new jasmineUnderTest.StringContaining('x');
const matcher = new jasmineUnderTest.StringContaining('x');
expect(matcher.asymmetricMatch(['x'])).toBe(false);
});
it("jasmineToString's itself", function() {
var matching = new jasmineUnderTest.StringContaining('foo');
const matching = new jasmineUnderTest.StringContaining('foo');
expect(matching.jasmineToString()).toEqual(
'<jasmine.stringContaining("foo")>'

View File

@@ -1,13 +1,13 @@
describe('StringMatching', function() {
it('matches a string against a provided regexp', function() {
var matcher = new jasmineUnderTest.StringMatching(/foo/);
const matcher = new jasmineUnderTest.StringMatching(/foo/);
expect(matcher.asymmetricMatch('barfoobaz')).toBe(true);
expect(matcher.asymmetricMatch('barbaz')).toBe(false);
});
it('matches a string against provided string', function() {
var matcher = new jasmineUnderTest.StringMatching('foo');
const matcher = new jasmineUnderTest.StringMatching('foo');
expect(matcher.asymmetricMatch('barfoobaz')).toBe(true);
expect(matcher.asymmetricMatch('barbaz')).toBe(false);
@@ -20,7 +20,7 @@ describe('StringMatching', function() {
});
it("jasmineToString's itself", function() {
var matching = new jasmineUnderTest.StringMatching(/^foo/);
const matching = new jasmineUnderTest.StringMatching(/^foo/);
expect(matching.jasmineToString()).toEqual(
'<jasmine.stringMatching(/^foo/)>'

View File

@@ -1,13 +1,13 @@
describe('Truthy', function() {
it('is true for a non empty string', function() {
var truthy = new jasmineUnderTest.Truthy();
const truthy = new jasmineUnderTest.Truthy();
expect(truthy.asymmetricMatch('foo')).toBe(true);
expect(truthy.asymmetricMatch('')).toBe(false);
});
it('is true for a number that is not 0', function() {
var truthy = new jasmineUnderTest.Truthy();
const truthy = new jasmineUnderTest.Truthy();
expect(truthy.asymmetricMatch(1)).toBe(true);
expect(truthy.asymmetricMatch(0)).toBe(false);
@@ -16,44 +16,44 @@ describe('Truthy', function() {
});
it('is true for a function', function() {
var truthy = new jasmineUnderTest.Truthy();
const truthy = new jasmineUnderTest.Truthy();
expect(truthy.asymmetricMatch(function() {})).toBe(true);
});
it('is true for an Object', function() {
var truthy = new jasmineUnderTest.Truthy();
const truthy = new jasmineUnderTest.Truthy();
expect(truthy.asymmetricMatch({})).toBe(true);
});
it('is true for a truthful Boolean', function() {
var truthy = new jasmineUnderTest.Truthy();
const truthy = new jasmineUnderTest.Truthy();
expect(truthy.asymmetricMatch(true)).toBe(true);
expect(truthy.asymmetricMatch(false)).toBe(false);
});
it('is true for an empty object', function() {
var truthy = new jasmineUnderTest.Truthy();
const truthy = new jasmineUnderTest.Truthy();
expect(truthy.asymmetricMatch({})).toBe(true);
});
it('is true for an empty array', function() {
var truthy = new jasmineUnderTest.Truthy();
const truthy = new jasmineUnderTest.Truthy();
expect(truthy.asymmetricMatch([])).toBe(true);
});
it('is true for a date', function() {
var truthy = new jasmineUnderTest.Truthy();
const truthy = new jasmineUnderTest.Truthy();
expect(truthy.asymmetricMatch(new Date())).toBe(true);
});
it('is true for a infiniti', function() {
var truthy = new jasmineUnderTest.Truthy();
const truthy = new jasmineUnderTest.Truthy();
expect(truthy.asymmetricMatch(Infinity)).toBe(true);
expect(truthy.asymmetricMatch(-Infinity)).toBe(true);