Removed deprecated custom matcher, matchersUtil, pp, etc interfaces
This commit is contained in:
committed by
Steve Gravrock
parent
66189d742b
commit
4b2a14f1f3
@@ -55,43 +55,6 @@ describe('Expectation', function() {
|
||||
expect(matcherFactory).toHaveBeenCalledWith(matchersUtil);
|
||||
});
|
||||
|
||||
// TODO: remove this in the next major release
|
||||
it('passes custom equality testers when the matcher factory takes two arguments', function() {
|
||||
var fakeCompare = function() {
|
||||
return { pass: true };
|
||||
},
|
||||
matcherFactory = function(matchersUtil, customTesters) {
|
||||
return { compare: fakeCompare };
|
||||
},
|
||||
matcherFactorySpy = jasmine
|
||||
.createSpy('matcher', matcherFactory)
|
||||
.and.callThrough(),
|
||||
matchers = {
|
||||
toFoo: matcherFactorySpy
|
||||
},
|
||||
matchersUtil = {
|
||||
buildFailureMessage: jasmine.createSpy('buildFailureMessage')
|
||||
},
|
||||
customEqualityTesters = ['a'],
|
||||
addExpectationResult = jasmine.createSpy('addExpectationResult'),
|
||||
expectation;
|
||||
|
||||
expectation = jasmineUnderTest.Expectation.factory({
|
||||
matchersUtil: matchersUtil,
|
||||
customMatchers: matchers,
|
||||
customEqualityTesters: customEqualityTesters,
|
||||
actual: 'an actual',
|
||||
addExpectationResult: addExpectationResult
|
||||
});
|
||||
|
||||
expectation.toFoo('hello');
|
||||
|
||||
expect(matcherFactorySpy).toHaveBeenCalledWith(
|
||||
matchersUtil,
|
||||
customEqualityTesters
|
||||
);
|
||||
});
|
||||
|
||||
it("wraps matchers's compare functions, passing the actual and expected", function() {
|
||||
var fakeCompare = jasmine
|
||||
.createSpy('fake-compare')
|
||||
|
||||
@@ -1,197 +0,0 @@
|
||||
describe('asymmetricEqualityTesterArgCompatShim', function() {
|
||||
it('provides all the properties of the MatchersUtil', function() {
|
||||
var matchersUtil = {
|
||||
foo: function() {},
|
||||
bar: function() {}
|
||||
},
|
||||
shim = jasmineUnderTest.asymmetricEqualityTesterArgCompatShim(
|
||||
matchersUtil,
|
||||
[]
|
||||
);
|
||||
|
||||
expect(shim.foo).toBe(matchersUtil.foo);
|
||||
expect(shim.bar).toBe(matchersUtil.bar);
|
||||
});
|
||||
|
||||
it('provides and deprecates all the properties of the customEqualityTesters', function() {
|
||||
var customEqualityTesters = [function() {}, function() {}],
|
||||
shim = jasmineUnderTest.asymmetricEqualityTesterArgCompatShim(
|
||||
{},
|
||||
customEqualityTesters
|
||||
),
|
||||
deprecated = spyOn(jasmineUnderTest.getEnv(), 'deprecated'),
|
||||
expectedMessage =
|
||||
'The second argument to asymmetricMatch is now a MatchersUtil. ' +
|
||||
'Using it as an array of custom equality testers is deprecated and will stop ' +
|
||||
'working in a future release. ' +
|
||||
'See <https://jasmine.github.io/tutorials/upgrading_to_4.0> for details.';
|
||||
|
||||
expect(shim.length).toBe(2);
|
||||
expect(deprecated).toHaveBeenCalledWith(expectedMessage);
|
||||
deprecated.calls.reset();
|
||||
|
||||
expect(shim[0]).toBe(customEqualityTesters[0]);
|
||||
expect(deprecated).toHaveBeenCalledWith(expectedMessage);
|
||||
deprecated.calls.reset();
|
||||
|
||||
expect(shim[1]).toBe(customEqualityTesters[1]);
|
||||
expect(deprecated).toHaveBeenCalledWith(expectedMessage);
|
||||
});
|
||||
|
||||
it('provides and deprecates all the properties of Array.prototype', function() {
|
||||
var shim = jasmineUnderTest.asymmetricEqualityTesterArgCompatShim({}, []),
|
||||
deprecated = spyOn(jasmineUnderTest.getEnv(), 'deprecated'),
|
||||
expectedMessage =
|
||||
'The second argument to asymmetricMatch is now a MatchersUtil. ' +
|
||||
'Using it as an array of custom equality testers is deprecated and will stop ' +
|
||||
'working in a future release. ' +
|
||||
'See <https://jasmine.github.io/tutorials/upgrading_to_4.0> for details.';
|
||||
|
||||
expect(shim.filter).toBe(Array.prototype.filter);
|
||||
expect(deprecated).toHaveBeenCalledWith(expectedMessage);
|
||||
deprecated.calls.reset();
|
||||
|
||||
expect(shim.forEach).toBe(Array.prototype.forEach);
|
||||
expect(deprecated).toHaveBeenCalledWith(expectedMessage);
|
||||
deprecated.calls.reset();
|
||||
|
||||
expect(shim.map).toBe(Array.prototype.map);
|
||||
expect(deprecated).toHaveBeenCalledWith(expectedMessage);
|
||||
deprecated.calls.reset();
|
||||
});
|
||||
|
||||
it('provides and deprecates properties of Array.prototype', function() {
|
||||
var keys = [
|
||||
'concat',
|
||||
'every',
|
||||
'filter',
|
||||
'forEach',
|
||||
'indexOf',
|
||||
'join',
|
||||
'lastIndexOf',
|
||||
'length',
|
||||
'map',
|
||||
'pop',
|
||||
'push',
|
||||
'reduce',
|
||||
'reduceRight',
|
||||
'reverse',
|
||||
'shift',
|
||||
'slice',
|
||||
'some',
|
||||
'sort',
|
||||
'splice',
|
||||
'unshift'
|
||||
],
|
||||
optionalKeys = [
|
||||
'copyWithin',
|
||||
'entries',
|
||||
'fill',
|
||||
'find',
|
||||
'findIndex',
|
||||
'flat',
|
||||
'flatMap',
|
||||
'includes',
|
||||
'keys',
|
||||
'values'
|
||||
],
|
||||
shim = jasmineUnderTest.asymmetricEqualityTesterArgCompatShim({}, []),
|
||||
deprecated = spyOn(jasmineUnderTest.getEnv(), 'deprecated'),
|
||||
i,
|
||||
k;
|
||||
|
||||
// Properties that are present on all supported runtimes
|
||||
for (i = 0; i < keys.length; i++) {
|
||||
k = keys[i];
|
||||
expect(shim[k])
|
||||
.withContext(k)
|
||||
.not.toBeUndefined();
|
||||
expect(shim[k])
|
||||
.withContext(k)
|
||||
.toBe(Array.prototype[k]);
|
||||
expect(deprecated).toHaveBeenCalled();
|
||||
deprecated.calls.reset();
|
||||
}
|
||||
|
||||
// Properties that are present on only some supported runtimes
|
||||
for (i = 0; i < optionalKeys.length; i++) {
|
||||
k = optionalKeys[i];
|
||||
|
||||
if (shim[k] !== undefined) {
|
||||
expect(shim[k])
|
||||
.withContext(k)
|
||||
.toBe(Array.prototype[k]);
|
||||
expect(deprecated)
|
||||
.withContext(k)
|
||||
.toHaveBeenCalled();
|
||||
deprecated.calls.reset();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
it('does not deprecate properties of Object.prototype', function() {
|
||||
var shim = jasmineUnderTest.asymmetricEqualityTesterArgCompatShim({}, []),
|
||||
deprecated = spyOn(jasmineUnderTest.getEnv(), 'deprecated');
|
||||
|
||||
expect(shim.hasOwnProperty).toBe(Object.prototype.hasOwnProperty);
|
||||
expect(shim.isPrototypeOf).toBe(Object.prototype.isPrototypeOf);
|
||||
|
||||
expect(deprecated).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
describe('When Array.prototype additions collide with MatchersUtil methods', function() {
|
||||
function keys() {
|
||||
return [
|
||||
'contains',
|
||||
'buildFailureMessage',
|
||||
'asymmetricDiff_',
|
||||
'asymmetricMatch_',
|
||||
'equals',
|
||||
'eq_'
|
||||
];
|
||||
}
|
||||
|
||||
beforeEach(function() {
|
||||
keys().forEach(function(k) {
|
||||
expect(Array.prototype[k])
|
||||
.withContext('Array.prototype already had ' + k)
|
||||
.toBeUndefined();
|
||||
Array.prototype[k] = function() {};
|
||||
});
|
||||
});
|
||||
|
||||
afterEach(function() {
|
||||
keys().forEach(function(k) {
|
||||
delete Array.prototype[k];
|
||||
});
|
||||
});
|
||||
|
||||
it('uses the MatchersUtil methods', function() {
|
||||
var matchersUtil = new jasmineUnderTest.MatchersUtil({}),
|
||||
shim = jasmineUnderTest.asymmetricEqualityTesterArgCompatShim(
|
||||
matchersUtil,
|
||||
[]
|
||||
);
|
||||
|
||||
keys().forEach(function(k) {
|
||||
expect(shim[k])
|
||||
.withContext(k + ' was overwritten')
|
||||
.toBe(jasmineUnderTest.MatchersUtil.prototype[k]);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('When the matchersUtil is already an asymmetricEqualityTesterArgCompatShim', function() {
|
||||
it('does not trigger any deprecations', function() {
|
||||
var shim1 = jasmineUnderTest.asymmetricEqualityTesterArgCompatShim(
|
||||
{},
|
||||
[]
|
||||
);
|
||||
spyOn(jasmineUnderTest.getEnv(), 'deprecated');
|
||||
|
||||
jasmineUnderTest.asymmetricEqualityTesterArgCompatShim(shim1, []);
|
||||
|
||||
expect(jasmineUnderTest.getEnv().deprecated).not.toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -124,48 +124,6 @@ describe('Custom Async Matchers (Integration)', function() {
|
||||
env.execute(null, done);
|
||||
});
|
||||
|
||||
// TODO: remove this in the next major release.
|
||||
describe('When a matcher factory takes at least two arguments', function() {
|
||||
it('passes the jasmine utility and current equality testers to the matcher factory', function(done) {
|
||||
jasmine.getEnv().requirePromises();
|
||||
|
||||
var matcherFactory = function(util, customTesters) {
|
||||
return {
|
||||
compare: function() {
|
||||
return Promise.resolve({ pass: true });
|
||||
}
|
||||
};
|
||||
},
|
||||
matcherFactorySpy = jasmine.createSpy(
|
||||
'matcherFactorySpy',
|
||||
matcherFactory
|
||||
),
|
||||
customEqualityFn = function() {
|
||||
return true;
|
||||
};
|
||||
|
||||
env.it('spec with expectation', function() {
|
||||
env.addCustomEqualityTester(customEqualityFn);
|
||||
env.addAsyncMatchers({
|
||||
toBeReal: matcherFactorySpy
|
||||
});
|
||||
|
||||
return env.expectAsync(true).toBeReal();
|
||||
});
|
||||
|
||||
var specExpectations = function() {
|
||||
expect(matcherFactorySpy).toHaveBeenCalledWith(
|
||||
jasmine.any(jasmineUnderTest.MatchersUtil),
|
||||
[customEqualityFn]
|
||||
);
|
||||
};
|
||||
|
||||
spyOn(env, 'deprecated');
|
||||
env.addReporter({ specDone: specExpectations, jasmineDone: done });
|
||||
env.execute();
|
||||
});
|
||||
});
|
||||
|
||||
it('provides custom equality testers to the matcher factory via matchersUtil', function(done) {
|
||||
jasmine.getEnv().requirePromises();
|
||||
|
||||
@@ -201,42 +159,4 @@ describe('Custom Async Matchers (Integration)', function() {
|
||||
env.addReporter({ specDone: specExpectations });
|
||||
env.execute(null, done);
|
||||
});
|
||||
|
||||
it('logs a deprecation once per matcher if the matcher factory takes two arguments', function(done) {
|
||||
var matcherFactory = function(matchersUtil, customEqualityTesters) {
|
||||
return { compare: function() {} };
|
||||
};
|
||||
|
||||
spyOn(env, 'deprecated');
|
||||
|
||||
env.beforeEach(function() {
|
||||
env.addAsyncMatchers({ toBeFoo: matcherFactory });
|
||||
env.addAsyncMatchers({ toBeBar: matcherFactory });
|
||||
});
|
||||
|
||||
env.it('a spec', function() {});
|
||||
env.it('another spec', function() {});
|
||||
|
||||
function jasmineDone() {
|
||||
expect(env.deprecated).toHaveBeenCalledWith(
|
||||
jasmine.stringMatching(
|
||||
'The matcher factory for "toBeFoo" accepts custom equality testers, ' +
|
||||
'but this parameter will no longer be passed in a future release. ' +
|
||||
'See <https://jasmine.github.io/tutorials/upgrading_to_4.0> for details.'
|
||||
)
|
||||
);
|
||||
expect(env.deprecated).toHaveBeenCalledWith(
|
||||
jasmine.stringMatching(
|
||||
'The matcher factory for "toBeBar" accepts custom equality testers, ' +
|
||||
'but this parameter will no longer be passed in a future release. ' +
|
||||
'See <https://jasmine.github.io/tutorials/upgrading_to_4.0> for details.'
|
||||
)
|
||||
);
|
||||
expect(env.deprecated).toHaveBeenCalledTimes(2);
|
||||
done();
|
||||
}
|
||||
|
||||
env.addReporter({ jasmineDone: jasmineDone });
|
||||
env.execute();
|
||||
});
|
||||
});
|
||||
|
||||
@@ -108,44 +108,7 @@ describe('Custom Matchers (Integration)', function() {
|
||||
env.execute(null, done);
|
||||
});
|
||||
|
||||
it('supports asymmetric equality testers that take a list of custom equality testers', function(done) {
|
||||
// TODO: remove this in the next major release.
|
||||
spyOn(jasmineUnderTest, 'getEnv').and.returnValue(env);
|
||||
spyOn(env, 'deprecated'); // suppress warnings
|
||||
|
||||
env.it('spec using custom asymmetric equality tester', function() {
|
||||
var customEqualityFn = function(a, b) {
|
||||
if (a === 2 && b === 'two') {
|
||||
return true;
|
||||
}
|
||||
};
|
||||
var arrayWithFirstElement = function(sample) {
|
||||
return {
|
||||
asymmetricMatch: function(actual, customEqualityTesters) {
|
||||
return jasmineUnderTest.matchersUtil.equals(
|
||||
sample,
|
||||
actual[0],
|
||||
customEqualityTesters
|
||||
);
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
env.addCustomEqualityTester(customEqualityFn);
|
||||
env.expect(['two']).toEqual(arrayWithFirstElement(2));
|
||||
});
|
||||
|
||||
var specExpectations = function(result) {
|
||||
expect(result.status).toEqual('passed');
|
||||
};
|
||||
|
||||
env.addReporter({ specDone: specExpectations });
|
||||
env.execute(null, done);
|
||||
});
|
||||
|
||||
it('displays an appropriate failure message if a custom equality matcher fails', function(done) {
|
||||
spyOn(env, 'deprecated');
|
||||
|
||||
env.it('spec using custom equality matcher', function() {
|
||||
var customEqualityFn = function(a, b) {
|
||||
// "foo" is not equal to anything
|
||||
@@ -277,47 +240,6 @@ describe('Custom Matchers (Integration)', function() {
|
||||
env.execute(null, done);
|
||||
});
|
||||
|
||||
// TODO: remove this in the next major release.
|
||||
describe('When a matcher factory takes at least two arguments', function() {
|
||||
it('passes the jasmine utility and current equality testers to the matcher factory', function(done) {
|
||||
spyOn(env, 'deprecated');
|
||||
|
||||
var matcherFactory = function(util, customTesters) {
|
||||
return {
|
||||
compare: function() {
|
||||
return { pass: true };
|
||||
}
|
||||
};
|
||||
},
|
||||
matcherFactorySpy = jasmine.createSpy(
|
||||
'matcherFactorySpy',
|
||||
matcherFactory
|
||||
),
|
||||
customEqualityFn = function() {
|
||||
return true;
|
||||
};
|
||||
|
||||
env.it('spec with expectation', function() {
|
||||
env.addCustomEqualityTester(customEqualityFn);
|
||||
env.addMatchers({
|
||||
toBeReal: matcherFactorySpy
|
||||
});
|
||||
|
||||
env.expect(true).toBeReal();
|
||||
});
|
||||
|
||||
var specExpectations = function() {
|
||||
expect(matcherFactorySpy).toHaveBeenCalledWith(
|
||||
jasmine.any(jasmineUnderTest.MatchersUtil),
|
||||
[customEqualityFn]
|
||||
);
|
||||
};
|
||||
|
||||
env.addReporter({ specDone: specExpectations, jasmineDone: done });
|
||||
env.execute();
|
||||
});
|
||||
});
|
||||
|
||||
it('provides custom equality testers to the matcher factory via matchersUtil', function(done) {
|
||||
var matcherFactory = function(matchersUtil) {
|
||||
return {
|
||||
@@ -349,42 +271,4 @@ describe('Custom Matchers (Integration)', function() {
|
||||
env.addReporter({ specDone: specExpectations });
|
||||
env.execute(null, done);
|
||||
});
|
||||
|
||||
it('logs a deprecation once per matcher if the matcher factory takes two arguments', function(done) {
|
||||
var matcherFactory = function(matchersUtil, customEqualityTesters) {
|
||||
return { compare: function() {} };
|
||||
};
|
||||
|
||||
spyOn(env, 'deprecated');
|
||||
|
||||
env.beforeEach(function() {
|
||||
env.addMatchers({ toBeFoo: matcherFactory });
|
||||
env.addMatchers({ toBeBar: matcherFactory });
|
||||
});
|
||||
|
||||
env.it('a spec', function() {});
|
||||
env.it('another spec', function() {});
|
||||
|
||||
function jasmineDone() {
|
||||
expect(env.deprecated).toHaveBeenCalledWith(
|
||||
jasmine.stringMatching(
|
||||
'The matcher factory for "toBeFoo" accepts custom equality testers, ' +
|
||||
'but this parameter will no longer be passed in a future release. ' +
|
||||
'See <https://jasmine.github.io/tutorials/upgrading_to_4.0> for details.'
|
||||
)
|
||||
);
|
||||
expect(env.deprecated).toHaveBeenCalledWith(
|
||||
jasmine.stringMatching(
|
||||
'The matcher factory for "toBeBar" accepts custom equality testers, ' +
|
||||
'but this parameter will no longer be passed in a future release. ' +
|
||||
'See <https://jasmine.github.io/tutorials/upgrading_to_4.0> for details.'
|
||||
)
|
||||
);
|
||||
expect(env.deprecated).toHaveBeenCalledTimes(2);
|
||||
done();
|
||||
}
|
||||
|
||||
env.addReporter({ jasmineDone: jasmineDone });
|
||||
env.execute();
|
||||
});
|
||||
});
|
||||
|
||||
@@ -499,19 +499,7 @@ describe('matchersUtil', function() {
|
||||
).toBe(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();
|
||||
|
||||
spyOn(jasmineUnderTest.getEnv(), 'deprecated'); // suppress warning
|
||||
|
||||
expect(matchersUtil.equals(1, 2, [tester])).toBe(true);
|
||||
});
|
||||
|
||||
it('passes when a custom equality matcher passed to the constructor returns true', function() {
|
||||
it('passes when a custom equality matcher returns true', function() {
|
||||
var tester = function(a, b) {
|
||||
return true;
|
||||
},
|
||||
@@ -528,20 +516,7 @@ describe('matchersUtil', function() {
|
||||
expect(matchersUtil.equals({}, {})).toBe(true);
|
||||
});
|
||||
|
||||
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() {
|
||||
var matchersUtil = new jasmineUnderTest.MatchersUtil();
|
||||
spyOn(jasmineUnderTest.getEnv(), 'deprecated'); // suppress warning
|
||||
expect(matchersUtil.equals({}, {}, [tester])).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
describe("when a custom equality matcher is passed to the constructor that returns 'undefined'", function() {
|
||||
describe("when a custom equality matcher returns 'undefined'", function() {
|
||||
var tester = function(a, b) {
|
||||
return jasmine.undefined;
|
||||
};
|
||||
@@ -555,19 +530,7 @@ describe('matchersUtil', 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();
|
||||
|
||||
spyOn(jasmineUnderTest.getEnv(), 'deprecated'); // suppress warning
|
||||
|
||||
expect(matchersUtil.equals(1, 1, [tester])).toBe(false);
|
||||
});
|
||||
|
||||
it('fails for equivalents when a custom equality matcher passed to the constructor returns false', function() {
|
||||
it('fails for equivalents when a custom equality matcher returns false', function() {
|
||||
var tester = function(a, b) {
|
||||
return false;
|
||||
},
|
||||
@@ -579,29 +542,7 @@ describe('matchersUtil', 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;
|
||||
},
|
||||
matchersUtil = new jasmineUnderTest.MatchersUtil();
|
||||
|
||||
spyOn(jasmineUnderTest.getEnv(), 'deprecated'); // suppress warning
|
||||
|
||||
expect(
|
||||
matchersUtil.equals(asymmetricTester, true, [symmetricTester])
|
||||
).toBe(true);
|
||||
expect(
|
||||
matchersUtil.equals(true, asymmetricTester, [symmetricTester])
|
||||
).toBe(true);
|
||||
});
|
||||
|
||||
it('passes for an asymmetric equality tester that returns true when a custom equality tester passed to the constructor return false', function() {
|
||||
it('passes for an asymmetric equality tester that returns true when a custom equality tester return false', function() {
|
||||
var asymmetricTester = {
|
||||
asymmetricMatch: function(other) {
|
||||
return true;
|
||||
@@ -619,47 +560,6 @@ describe('matchersUtil', function() {
|
||||
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;
|
||||
|
||||
spyOn(jasmineUnderTest.getEnv(), 'deprecated'); // suppress warning
|
||||
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;
|
||||
|
||||
spyOn(jasmineUnderTest.getEnv(), 'deprecated'); // suppress warning
|
||||
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),
|
||||
@@ -1030,57 +930,6 @@ describe('matchersUtil', function() {
|
||||
});
|
||||
});
|
||||
|
||||
it('logs a deprecation warning when custom equality testers are passed', function() {
|
||||
var matchersUtil = new jasmineUnderTest.MatchersUtil(),
|
||||
deprecated = spyOn(jasmineUnderTest.getEnv(), 'deprecated');
|
||||
|
||||
matchersUtil.equals(0, 0, []);
|
||||
|
||||
expect(deprecated).toHaveBeenCalledWith(
|
||||
jasmine.stringMatching(
|
||||
'Passing custom equality testers ' +
|
||||
'to MatchersUtil#equals is deprecated. ' +
|
||||
'See <https://jasmine.github.io/tutorials/upgrading_to_4.0> for details.'
|
||||
)
|
||||
);
|
||||
});
|
||||
|
||||
it('logs a deprecation warning when a diffBuilder is provided as the fourth argument', function() {
|
||||
var matchersUtil = new jasmineUnderTest.MatchersUtil(),
|
||||
deprecated = spyOn(jasmineUnderTest.getEnv(), 'deprecated');
|
||||
|
||||
matchersUtil.equals(0, 0, null, new jasmineUnderTest.NullDiffBuilder());
|
||||
|
||||
expect(deprecated).toHaveBeenCalledWith(
|
||||
jasmine.stringMatching(
|
||||
'Diff builder should be passed as the ' +
|
||||
'third argument to MatchersUtil#equals, not the fourth. ' +
|
||||
'See <https://jasmine.github.io/tutorials/upgrading_to_4.0> for details.'
|
||||
)
|
||||
);
|
||||
});
|
||||
|
||||
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(jasmineUnderTest.getEnv(), 'deprecated'); // suppress warning
|
||||
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();
|
||||
@@ -1130,25 +979,7 @@ describe('matchersUtil', function() {
|
||||
).toBe(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(),
|
||||
deprecated = spyOn(jasmineUnderTest.getEnv(), 'deprecated');
|
||||
|
||||
expect(matchersUtil.contains([1, 2], 3, [customTester])).toBe(true);
|
||||
|
||||
expect(deprecated).toHaveBeenCalledWith(
|
||||
jasmine.stringMatching(
|
||||
'Passing custom equality testers to MatchersUtil#contains is deprecated. ' +
|
||||
'See <https://jasmine.github.io/tutorials/upgrading_to_4.0> for details.'
|
||||
)
|
||||
);
|
||||
});
|
||||
|
||||
it('uses custom equality testers if passed to the constructor and actual is an Array', function() {
|
||||
it('uses custom equality testers if actual is an Array', function() {
|
||||
var customTester = function(a, b) {
|
||||
return true;
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user