Allow libraries to avoid "Passing custom equality testers to MatchersUtil#contains is deprecated" while remaining compatible with older jasmine versions
Previously, a custom matcher library that wanted to remain compatible with
Jasmine <= 3.5.x could not know whether or not Jasmine expected it to pass
custom equality testers to MatchersUtil#contains. Passing them would produce
a deprecation warning in newer versions and not passing them would break
compatibility with older versions. Now we use matcher factory arity to
determine whether to pass custom equality testers to the factory, which
allows libraries to do something like this:
function matcherFactory(util) {
const customEqualityTesters = arguments[1];
// customEqualityTesters will be undefined in newer versions of Jasmine
// and defined in older versions that expect it to be passed back to
// MatchersUtil#equals.
}
This commit is contained in:
committed by
Steve Gravrock
parent
9aed55bb91
commit
18b2646d1d
@@ -80,24 +80,19 @@ describe('Custom Async Matchers (Integration)', function() {
|
||||
env.execute();
|
||||
});
|
||||
|
||||
// TODO: remove this in the next major release.
|
||||
it("passes the jasmine utility and current equality testers to the matcher factory", function(done) {
|
||||
it("passes the jasmine utility to the matcher factory", function (done) {
|
||||
jasmine.getEnv().requirePromises();
|
||||
|
||||
var matcherFactory = function () {
|
||||
var matcherFactory = function (util) {
|
||||
return {
|
||||
compare: function () {
|
||||
return Promise.resolve({pass: true});
|
||||
}
|
||||
};
|
||||
},
|
||||
matcherFactorySpy = jasmine.createSpy("matcherFactorySpy").and.callFake(matcherFactory),
|
||||
customEqualityFn = function () {
|
||||
return true;
|
||||
};
|
||||
matcherFactorySpy = jasmine.createSpy("matcherFactorySpy", matcherFactory);
|
||||
|
||||
env.it("spec with expectation", function() {
|
||||
env.addCustomEqualityTester(customEqualityFn);
|
||||
env.it("spec with expectation", function () {
|
||||
env.addAsyncMatchers({
|
||||
toBeReal: matcherFactorySpy
|
||||
});
|
||||
@@ -105,17 +100,55 @@ describe('Custom Async Matchers (Integration)', function() {
|
||||
return env.expectAsync(true).toBeReal();
|
||||
});
|
||||
|
||||
var specExpectations = function() {
|
||||
var specExpectations = function () {
|
||||
expect(matcherFactorySpy).toHaveBeenCalledWith(
|
||||
jasmine.any(jasmineUnderTest.MatchersUtil),
|
||||
[customEqualityFn]
|
||||
jasmine.any(jasmineUnderTest.MatchersUtil)
|
||||
);
|
||||
};
|
||||
|
||||
env.addReporter({ specDone: specExpectations, jasmineDone: done });
|
||||
env.addReporter({specDone: specExpectations, jasmineDone: done});
|
||||
env.execute();
|
||||
});
|
||||
|
||||
// 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();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user