Added deprecation messages to interfaces that will be removed in 4.0

* `jasmine.pp`
* `jasmine.matchersUtil`
* Matchers that expect to receive custom equality testers
* Passing custom equality testers to `matchersUtil.contains`
* Passing custom equality testers to `matchersUtil.equals`
This commit is contained in:
Steve Gravrock
2019-11-28 10:50:55 -08:00
committed by Steve Gravrock
parent 258d55469e
commit 90d6f9d73c
16 changed files with 321 additions and 49 deletions

View File

@@ -13,27 +13,54 @@ describe('asymmetricEqualityTesterArgCompatShim', function() {
expect(shim.bar).toBe(matchersUtil.bar);
});
it('provides all the properties of the customEqualityTesters', function() {
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 all the properties of Array.prototype', function() {
var shim = jasmineUnderTest.asymmetricEqualityTesterArgCompatShim({}, []);
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 properties of Array.prototype', function() {
it('provides and deprecates properties of Array.prototype', function() {
var keys = [
'concat',
'constructor',
@@ -73,6 +100,7 @@ describe('asymmetricEqualityTesterArgCompatShim', function() {
'values'
],
shim = jasmineUnderTest.asymmetricEqualityTesterArgCompatShim({}, []),
deprecated = spyOn(jasmineUnderTest.getEnv(), 'deprecated'),
i,
k;
@@ -85,6 +113,8 @@ describe('asymmetricEqualityTesterArgCompatShim', function() {
expect(shim[k])
.withContext(k)
.toBe(Array.prototype[k]);
expect(deprecated).toHaveBeenCalled();
deprecated.calls.reset();
}
// Properties that are present on only some supported runtimes
@@ -95,7 +125,21 @@ describe('asymmetricEqualityTesterArgCompatShim', function() {
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();
});
});

View File

@@ -147,4 +147,27 @@ describe('Custom Async Matchers (Integration)', function() {
env.addReporter({ specDone: specExpectations, jasmineDone: done });
env.execute();
});
it('logs a deprecation warning if the matcher factory takes two arguments', function (done) {
var matcherFactory = function (matchersUtil, customEqualityTesters) {
return { compare: function () {} };
};
spyOn(env, 'deprecated');
env.it('a spec', function() {
env.addAsyncMatchers({toBeFoo: matcherFactory});
});
function jasmineDone() {
expect(env.deprecated).toHaveBeenCalledWith('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.');
done();
}
env.addReporter({jasmineDone: jasmineDone});
env.execute();
});
});

View File

@@ -88,6 +88,7 @@ describe("Custom Matchers (Integration)", function () {
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) {
@@ -265,4 +266,27 @@ describe("Custom Matchers (Integration)", function () {
env.addReporter({specDone: specExpectations, jasmineDone: done});
env.execute();
});
it('logs a deprecation warning if the matcher factory takes two arguments', function(done) {
var matcherFactory = function (matchersUtil, customEqualityTesters) {
return { compare: function() {} };
};
spyOn(env, 'deprecated');
env.it('a spec', function() {
env.addMatchers({toBeFoo: matcherFactory});
});
function jasmineDone() {
expect(env.deprecated).toHaveBeenCalledWith('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.');
done();
}
env.addReporter({jasmineDone: jasmineDone});
env.execute();
});
});

View File

@@ -44,14 +44,16 @@ describe("matchersUtil", function() {
}
it('is symmetric', function() {
var matchersUtil = new jasmineUnderTest.MatchersUtil();
fc.assert(
fc.property(
fc.anything(basicAnythingSettings()),
fc.anything(basicAnythingSettings()),
function(a, b) {
return (
jasmineUnderTest.matchersUtil.equals(a, b) ===
jasmineUnderTest.matchersUtil.equals(b, a)
matchersUtil.equals(a, b) ===
matchersUtil.equals(b, a)
);
}
),
@@ -63,13 +65,14 @@ describe("matchersUtil", function() {
});
it('is reflexive', function() {
var matchersUtil = new jasmineUnderTest.MatchersUtil();
var anythingSettings = basicAnythingSettings();
anythingSettings.withMap = false;
fc.assert(
fc.property(fc.dedup(fc.anything(anythingSettings), 2), function(
values
) {
return jasmineUnderTest.matchersUtil.equals(values[0], values[1]);
return matchersUtil.equals(values[0], values[1]);
}),
{
numRuns: numRuns()
@@ -465,6 +468,8 @@ describe("matchersUtil", function() {
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);
});
@@ -486,6 +491,7 @@ describe("matchersUtil", function() {
it("passes for two empty Objects", function () {
var matchersUtil = new jasmineUnderTest.MatchersUtil();
spyOn(jasmineUnderTest.getEnv(), 'deprecated'); // suppress warning
expect(matchersUtil.equals({}, {}, [tester])).toBe(true);
});
});
@@ -504,6 +510,8 @@ describe("matchersUtil", function() {
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);
});
@@ -520,6 +528,8 @@ describe("matchersUtil", function() {
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);
});
@@ -541,6 +551,7 @@ describe("matchersUtil", 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));
@@ -556,6 +567,7 @@ describe("matchersUtil", 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));
@@ -809,10 +821,11 @@ describe("matchersUtil", function() {
},
actual = {x: 42},
expected = {x: tester},
diffBuilder = jasmine.createSpyObj('diffBuilder', ['recordMismatch', 'withPath', 'setRoots']);
diffBuilder = jasmine.createSpyObj('diffBuilder', ['recordMismatch', 'withPath', 'setRoots']),
matchersUtil = new jasmineUnderTest.MatchersUtil();
diffBuilder.withPath.and.callFake(function(p, block) { block(); });
jasmineUnderTest.matchersUtil.equals(actual, expected, [], diffBuilder);
matchersUtil.equals(actual, expected, diffBuilder);
expect(diffBuilder.setRoots).toHaveBeenCalledWith(actual, expected);
expect(diffBuilder.withPath).toHaveBeenCalledWith('x', jasmine.any(Function));
@@ -825,9 +838,11 @@ describe("matchersUtil", function() {
},
actual = {x: 42},
expected = {x: tester},
diffBuilder = jasmine.createSpyObj('diffBuilder', ['recordMismatch', 'withPath', 'setRoots']);
diffBuilder = jasmine.createSpyObj('diffBuilder', ['recordMismatch', 'withPath', 'setRoots']),
matchersUtil = new jasmineUnderTest.MatchersUtil();
diffBuilder.withPath.and.callFake(function(p, block) { block(); });
jasmineUnderTest.matchersUtil.equals(actual, expected, [], diffBuilder);
matchersUtil.equals(actual, expected, diffBuilder);
expect(diffBuilder.setRoots).toHaveBeenCalledWith(actual, expected);
expect(diffBuilder.withPath).toHaveBeenCalledWith('x', jasmine.any(Function));
@@ -835,11 +850,34 @@ 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('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('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();
@@ -893,9 +931,14 @@ describe("matchersUtil", function() {
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();
matchersUtil = new jasmineUnderTest.MatchersUtil(),
deprecated = spyOn(jasmineUnderTest.getEnv(), 'deprecated');
expect(matchersUtil.contains([1, 2], 3, [customTester])).toBe(true);
expect(deprecated).toHaveBeenCalledWith('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() {