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
+86 -17
View File
@@ -77,11 +77,34 @@ var getJasmineRequireObj = (function(jasmineGlobal) {
j$ j$
); );
j$.makePrettyPrinter = jRequire.makePrettyPrinter(j$); j$.makePrettyPrinter = jRequire.makePrettyPrinter(j$);
j$.pp = j$.makePrettyPrinter(); j$.basicPrettyPrinter_ = j$.makePrettyPrinter();
Object.defineProperty(j$, 'pp', {
get: function() {
j$.getEnv().deprecated(
'jasmine.pp is deprecated and will be removed in a future release. ' +
'Use the pp method of the matchersUtil passed to the matcher factory ' +
"or the asymmetric equality tester's `asymmetricMatch` method " +
'instead. See ' +
'<https://jasmine.github.io/tutorials/upgrading_to_4.0> for details.'
);
return j$.basicPrettyPrinter_;
}
});
j$.MatchersUtil = jRequire.MatchersUtil(j$); j$.MatchersUtil = jRequire.MatchersUtil(j$);
j$.matchersUtil = new j$.MatchersUtil({ var staticMatchersUtil = new j$.MatchersUtil({
customTesters: [], customTesters: [],
pp: j$.pp pp: j$.basicPrettyPrinter_
});
Object.defineProperty(j$, 'matchersUtil', {
get: function() {
j$.getEnv().deprecated(
'jasmine.matchersUtil is deprecated and will be removed ' +
'in a future release. Use the instance passed to the matcher factory or ' +
"the asymmetric equality tester's `asymmetricMatch` method instead. " +
'See <https://jasmine.github.io/tutorials/upgrading_to_4.0> for details.'
);
return staticMatchersUtil;
}
}); });
j$.ObjectContaining = jRequire.ObjectContaining(j$); j$.ObjectContaining = jRequire.ObjectContaining(j$);
@@ -1204,6 +1227,17 @@ getJasmineRequireObj().Env = function(j$) {
runnableResources[currentRunnable().id].customMatchers; runnableResources[currentRunnable().id].customMatchers;
for (var matcherName in matchersToAdd) { for (var matcherName in matchersToAdd) {
if (matchersToAdd[matcherName].length > 1) {
self.deprecated(
'The matcher factory for "' +
matcherName +
'" ' +
'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.'
);
}
customMatchers[matcherName] = matchersToAdd[matcherName]; customMatchers[matcherName] = matchersToAdd[matcherName];
} }
}; };
@@ -1218,6 +1252,17 @@ getJasmineRequireObj().Env = function(j$) {
runnableResources[currentRunnable().id].customAsyncMatchers; runnableResources[currentRunnable().id].customAsyncMatchers;
for (var matcherName in matchersToAdd) { for (var matcherName in matchersToAdd) {
if (matchersToAdd[matcherName].length > 1) {
self.deprecated(
'The matcher factory for "' +
matcherName +
'" ' +
'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.'
);
}
customAsyncMatchers[matcherName] = matchersToAdd[matcherName]; customAsyncMatchers[matcherName] = matchersToAdd[matcherName];
} }
}; };
@@ -2360,7 +2405,7 @@ getJasmineRequireObj().ArrayContaining = function(j$) {
ArrayContaining.prototype.asymmetricMatch = function(other, matchersUtil) { ArrayContaining.prototype.asymmetricMatch = function(other, matchersUtil) {
if (!j$.isArray_(this.sample)) { if (!j$.isArray_(this.sample)) {
throw new Error('You must provide an array to arrayContaining, not ' + j$.pp(this.sample) + '.'); throw new Error('You must provide an array to arrayContaining, not ' + j$.basicPrettyPrinter_(this.sample) + '.');
} }
// If the actual parameter is not an array, we can fail immediately, since it couldn't // If the actual parameter is not an array, we can fail immediately, since it couldn't
@@ -2395,7 +2440,7 @@ getJasmineRequireObj().ArrayWithExactContents = function(j$) {
ArrayWithExactContents.prototype.asymmetricMatch = function(other, matchersUtil) { ArrayWithExactContents.prototype.asymmetricMatch = function(other, matchersUtil) {
if (!j$.isArray_(this.sample)) { if (!j$.isArray_(this.sample)) {
throw new Error('You must provide an array to arrayWithExactContents, not ' + j$.pp(this.sample) + '.'); throw new Error('You must provide an array to arrayWithExactContents, not ' + j$.basicPrettyPrinter_(this.sample) + '.');
} }
if (this.sample.length !== other.length) { if (this.sample.length !== other.length) {
@@ -2463,7 +2508,7 @@ getJasmineRequireObj().Falsy = function(j$) {
getJasmineRequireObj().MapContaining = function(j$) { getJasmineRequireObj().MapContaining = function(j$) {
function MapContaining(sample) { function MapContaining(sample) {
if (!j$.isMap(sample)) { if (!j$.isMap(sample)) {
throw new Error('You must provide a map to `mapContaining`, not ' + j$.pp(sample)); throw new Error('You must provide a map to `mapContaining`, not ' + j$.basicPrettyPrinter_(sample));
} }
this.sample = sample; this.sample = sample;
@@ -2604,7 +2649,7 @@ getJasmineRequireObj().ObjectContaining = function(j$) {
getJasmineRequireObj().SetContaining = function(j$) { getJasmineRequireObj().SetContaining = function(j$) {
function SetContaining(sample) { function SetContaining(sample) {
if (!j$.isSet(sample)) { if (!j$.isSet(sample)) {
throw new Error('You must provide a set to `setContaining`, not ' + j$.pp(sample)); throw new Error('You must provide a set to `setContaining`, not ' + j$.basicPrettyPrinter_(sample));
} }
this.sample = sample; this.sample = sample;
@@ -2735,10 +2780,10 @@ getJasmineRequireObj().asymmetricEqualityTesterArgCompatShim = function(j$) {
i, i,
k; k;
copy(self, customEqualityTesters, 'length'); copyAndDeprecate(self, customEqualityTesters, 'length');
for (i = 0; i < customEqualityTesters.length; i++) { for (i = 0; i < customEqualityTesters.length; i++) {
copy(self, customEqualityTesters, i); copyAndDeprecate(self, customEqualityTesters, i);
} }
var props = arrayProps(); var props = arrayProps();
@@ -2746,16 +2791,22 @@ getJasmineRequireObj().asymmetricEqualityTesterArgCompatShim = function(j$) {
for (i = 0; i < props.length; i++) { for (i = 0; i < props.length; i++) {
k = props[i]; k = props[i];
if (k !== 'length') { if (k !== 'length') {
copy(self, Array.prototype, k); copyAndDeprecate(self, Array.prototype, k);
} }
} }
return self; return self;
} }
function copy(dest, src, propName) { function copyAndDeprecate(dest, src, propName) {
Object.defineProperty(dest, propName, { Object.defineProperty(dest, propName, {
get: function() { get: function() {
j$.getEnv().deprecated(
'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.'
);
return src[propName]; return src[propName];
} }
}); });
@@ -3488,7 +3539,7 @@ getJasmineRequireObj().ExceptionFormatter = function(j$) {
} }
if (!empty) { if (!empty) {
return 'error properties: ' + j$.pp(result) + '\n'; return 'error properties: ' + j$.basicPrettyPrinter_(result) + '\n';
} }
return ''; return '';
@@ -4403,8 +4454,6 @@ getJasmineRequireObj().DiffBuilder = function (j$) {
}; };
getJasmineRequireObj().MatchersUtil = function(j$) { getJasmineRequireObj().MatchersUtil = function(j$) {
// TODO: convert all uses of j$.pp to use the injected pp
/** /**
* _Note:_ Do not construct this directly. Jasmine will construct one and * _Note:_ Do not construct this directly. Jasmine will construct one and
* pass it to matchers and asymmetric equality testers. * pass it to matchers and asymmetric equality testers.
@@ -4434,10 +4483,17 @@ getJasmineRequireObj().MatchersUtil = function(j$) {
* @name MatchersUtil#contains * @name MatchersUtil#contains
* @param {*} haystack The collection to search * @param {*} haystack The collection to search
* @param {*} needle The value to search for * @param {*} needle The value to search for
* @param [customTesters] An array of custom equality testers * @param [customTesters] An array of custom equality testers. Deprecated.
* As of 3.6 this parameter no longer needs to be passed. It will be removed in 4.0.
* @returns {boolean} True if `needle` was found in `haystack` * @returns {boolean} True if `needle` was found in `haystack`
*/ */
MatchersUtil.prototype.contains = function(haystack, needle, customTesters) { MatchersUtil.prototype.contains = function(haystack, needle, customTesters) {
if (customTesters) {
j$.getEnv().deprecated('Passing custom equality testers to ' +
'MatchersUtil#contains is deprecated. See ' +
'<https://jasmine.github.io/tutorials/upgrading_to_4.0> for details.');
}
if (j$.isSet(haystack)) { if (j$.isSet(haystack)) {
return haystack.has(needle); return haystack.has(needle);
} }
@@ -4526,7 +4582,8 @@ getJasmineRequireObj().MatchersUtil = function(j$) {
* @name MatchersUtil#equals * @name MatchersUtil#equals
* @param {*} a The first value to compare * @param {*} a The first value to compare
* @param {*} b The second value to compare * @param {*} b The second value to compare
* @param [customTesters] An array of custom equality testers * @param [customTesters] An array of custom equality testers. Deprecated.
* As of 3.6 this parameter no longer needs to be passed. It will be removed in 4.0.
* @returns {boolean} True if the values are equal * @returns {boolean} True if the values are equal
*/ */
MatchersUtil.prototype.equals = function(a, b, customTestersOrDiffBuilder, diffBuilderOrNothing) { MatchersUtil.prototype.equals = function(a, b, customTestersOrDiffBuilder, diffBuilderOrNothing) {
@@ -4535,6 +4592,18 @@ getJasmineRequireObj().MatchersUtil = function(j$) {
if (isDiffBuilder(customTestersOrDiffBuilder)) { if (isDiffBuilder(customTestersOrDiffBuilder)) {
diffBuilder = customTestersOrDiffBuilder; diffBuilder = customTestersOrDiffBuilder;
} else { } else {
if (customTestersOrDiffBuilder) {
j$.getEnv().deprecated('Passing custom equality testers to ' +
'MatchersUtil#equals is deprecated. See ' +
'<https://jasmine.github.io/tutorials/upgrading_to_4.0> for details.');
}
if (diffBuilderOrNothing) {
j$.getEnv().deprecated('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.');
}
customTesters = customTestersOrDiffBuilder; customTesters = customTestersOrDiffBuilder;
diffBuilder = diffBuilderOrNothing; diffBuilder = diffBuilderOrNothing;
} }
@@ -7563,7 +7632,7 @@ getJasmineRequireObj().Spy = function(j$) {
"Spy '" + "Spy '" +
strategyArgs.name + strategyArgs.name +
"' received a call with arguments " + "' received a call with arguments " +
j$.pp(Array.prototype.slice.call(args)) + j$.basicPrettyPrinter_(Array.prototype.slice.call(args)) +
' but all configured strategies specify other arguments.' ' but all configured strategies specify other arguments.'
); );
} else { } else {
@@ -13,27 +13,54 @@ describe('asymmetricEqualityTesterArgCompatShim', function() {
expect(shim.bar).toBe(matchersUtil.bar); 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() {}], var customEqualityTesters = [function() {}, function() {}],
shim = jasmineUnderTest.asymmetricEqualityTesterArgCompatShim( shim = jasmineUnderTest.asymmetricEqualityTesterArgCompatShim(
{}, {},
customEqualityTesters 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(shim.length).toBe(2);
expect(deprecated).toHaveBeenCalledWith(expectedMessage);
deprecated.calls.reset();
expect(shim[0]).toBe(customEqualityTesters[0]); expect(shim[0]).toBe(customEqualityTesters[0]);
expect(deprecated).toHaveBeenCalledWith(expectedMessage);
deprecated.calls.reset();
expect(shim[1]).toBe(customEqualityTesters[1]); expect(shim[1]).toBe(customEqualityTesters[1]);
expect(deprecated).toHaveBeenCalledWith(expectedMessage);
}); });
it('provides all the properties of Array.prototype', function() { it('provides and deprecates all the properties of Array.prototype', function() {
var shim = jasmineUnderTest.asymmetricEqualityTesterArgCompatShim({}, []); 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(shim.filter).toBe(Array.prototype.filter);
expect(deprecated).toHaveBeenCalledWith(expectedMessage);
deprecated.calls.reset();
expect(shim.forEach).toBe(Array.prototype.forEach); expect(shim.forEach).toBe(Array.prototype.forEach);
expect(deprecated).toHaveBeenCalledWith(expectedMessage);
deprecated.calls.reset();
expect(shim.map).toBe(Array.prototype.map); 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 = [ var keys = [
'concat', 'concat',
'constructor', 'constructor',
@@ -73,6 +100,7 @@ describe('asymmetricEqualityTesterArgCompatShim', function() {
'values' 'values'
], ],
shim = jasmineUnderTest.asymmetricEqualityTesterArgCompatShim({}, []), shim = jasmineUnderTest.asymmetricEqualityTesterArgCompatShim({}, []),
deprecated = spyOn(jasmineUnderTest.getEnv(), 'deprecated'),
i, i,
k; k;
@@ -85,6 +113,8 @@ describe('asymmetricEqualityTesterArgCompatShim', function() {
expect(shim[k]) expect(shim[k])
.withContext(k) .withContext(k)
.toBe(Array.prototype[k]); .toBe(Array.prototype[k]);
expect(deprecated).toHaveBeenCalled();
deprecated.calls.reset();
} }
// Properties that are present on only some supported runtimes // Properties that are present on only some supported runtimes
@@ -95,7 +125,21 @@ describe('asymmetricEqualityTesterArgCompatShim', function() {
expect(shim[k]) expect(shim[k])
.withContext(k) .withContext(k)
.toBe(Array.prototype[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();
});
}); });
@@ -147,4 +147,27 @@ describe('Custom Async Matchers (Integration)', function() {
env.addReporter({ specDone: specExpectations, jasmineDone: done }); env.addReporter({ specDone: specExpectations, jasmineDone: done });
env.execute(); 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();
});
}); });
@@ -88,6 +88,7 @@ describe("Custom Matchers (Integration)", function () {
it("supports asymmetric equality testers that take a list of custom equality testers", function(done) { it("supports asymmetric equality testers that take a list of custom equality testers", function(done) {
// TODO: remove this in the next major release. // TODO: remove this in the next major release.
spyOn(jasmineUnderTest, 'getEnv').and.returnValue(env); spyOn(jasmineUnderTest, 'getEnv').and.returnValue(env);
spyOn(env, 'deprecated'); // suppress warnings
env.it("spec using custom asymmetric equality tester", function() { env.it("spec using custom asymmetric equality tester", function() {
var customEqualityFn = function(a, b) { var customEqualityFn = function(a, b) {
@@ -265,4 +266,27 @@ describe("Custom Matchers (Integration)", function () {
env.addReporter({specDone: specExpectations, jasmineDone: done}); env.addReporter({specDone: specExpectations, jasmineDone: done});
env.execute(); 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();
});
}); });
+51 -8
View File
@@ -44,14 +44,16 @@ describe("matchersUtil", function() {
} }
it('is symmetric', function() { it('is symmetric', function() {
var matchersUtil = new jasmineUnderTest.MatchersUtil();
fc.assert( fc.assert(
fc.property( fc.property(
fc.anything(basicAnythingSettings()), fc.anything(basicAnythingSettings()),
fc.anything(basicAnythingSettings()), fc.anything(basicAnythingSettings()),
function(a, b) { function(a, b) {
return ( return (
jasmineUnderTest.matchersUtil.equals(a, b) === matchersUtil.equals(a, b) ===
jasmineUnderTest.matchersUtil.equals(b, a) matchersUtil.equals(b, a)
); );
} }
), ),
@@ -63,13 +65,14 @@ describe("matchersUtil", function() {
}); });
it('is reflexive', function() { it('is reflexive', function() {
var matchersUtil = new jasmineUnderTest.MatchersUtil();
var anythingSettings = basicAnythingSettings(); var anythingSettings = basicAnythingSettings();
anythingSettings.withMap = false; anythingSettings.withMap = false;
fc.assert( fc.assert(
fc.property(fc.dedup(fc.anything(anythingSettings), 2), function( fc.property(fc.dedup(fc.anything(anythingSettings), 2), function(
values values
) { ) {
return jasmineUnderTest.matchersUtil.equals(values[0], values[1]); return matchersUtil.equals(values[0], values[1]);
}), }),
{ {
numRuns: numRuns() numRuns: numRuns()
@@ -465,6 +468,8 @@ describe("matchersUtil", function() {
var tester = function(a, b) { return true; }, var tester = function(a, b) { return true; },
matchersUtil = new jasmineUnderTest.MatchersUtil(); matchersUtil = new jasmineUnderTest.MatchersUtil();
spyOn(jasmineUnderTest.getEnv(), 'deprecated'); // suppress warning
expect(matchersUtil.equals(1, 2, [tester])).toBe(true); expect(matchersUtil.equals(1, 2, [tester])).toBe(true);
}); });
@@ -486,6 +491,7 @@ describe("matchersUtil", function() {
it("passes for two empty Objects", function () { it("passes for two empty Objects", function () {
var matchersUtil = new jasmineUnderTest.MatchersUtil(); var matchersUtil = new jasmineUnderTest.MatchersUtil();
spyOn(jasmineUnderTest.getEnv(), 'deprecated'); // suppress warning
expect(matchersUtil.equals({}, {}, [tester])).toBe(true); expect(matchersUtil.equals({}, {}, [tester])).toBe(true);
}); });
}); });
@@ -504,6 +510,8 @@ describe("matchersUtil", function() {
var tester = function(a, b) { return false; }, var tester = function(a, b) { return false; },
matchersUtil = new jasmineUnderTest.MatchersUtil(); matchersUtil = new jasmineUnderTest.MatchersUtil();
spyOn(jasmineUnderTest.getEnv(), 'deprecated'); // suppress warning
expect(matchersUtil.equals(1, 1, [tester])).toBe(false); expect(matchersUtil.equals(1, 1, [tester])).toBe(false);
}); });
@@ -520,6 +528,8 @@ describe("matchersUtil", function() {
symmetricTester = function(a, b) { return false; }, symmetricTester = function(a, b) { return false; },
matchersUtil = new jasmineUnderTest.MatchersUtil(); matchersUtil = new jasmineUnderTest.MatchersUtil();
spyOn(jasmineUnderTest.getEnv(), 'deprecated'); // suppress warning
expect(matchersUtil.equals(asymmetricTester, true, [symmetricTester])).toBe(true); expect(matchersUtil.equals(asymmetricTester, true, [symmetricTester])).toBe(true);
expect(matchersUtil.equals(true, asymmetricTester, [symmetricTester])).toBe(true); expect(matchersUtil.equals(true, asymmetricTester, [symmetricTester])).toBe(true);
}); });
@@ -541,6 +551,7 @@ describe("matchersUtil", function() {
matchersUtil = new jasmineUnderTest.MatchersUtil(), matchersUtil = new jasmineUnderTest.MatchersUtil(),
shim; shim;
spyOn(jasmineUnderTest.getEnv(), 'deprecated'); // suppress warning
matchersUtil.equals(true, asymmetricTester, [symmetricTester]); matchersUtil.equals(true, asymmetricTester, [symmetricTester]);
shim = asymmetricTester.asymmetricMatch.calls.argsFor(0)[1]; shim = asymmetricTester.asymmetricMatch.calls.argsFor(0)[1];
expect(shim).toEqual(jasmine.any(jasmineUnderTest.MatchersUtil)); expect(shim).toEqual(jasmine.any(jasmineUnderTest.MatchersUtil));
@@ -556,6 +567,7 @@ describe("matchersUtil", function() {
matchersUtil = new jasmineUnderTest.MatchersUtil({customTesters: [symmetricTester], pp: function() {}}), matchersUtil = new jasmineUnderTest.MatchersUtil({customTesters: [symmetricTester], pp: function() {}}),
shim; shim;
spyOn(jasmineUnderTest.getEnv(), 'deprecated'); // suppress warning
matchersUtil.equals(true, asymmetricTester); matchersUtil.equals(true, asymmetricTester);
shim = asymmetricTester.asymmetricMatch.calls.argsFor(0)[1]; shim = asymmetricTester.asymmetricMatch.calls.argsFor(0)[1];
expect(shim).toEqual(jasmine.any(jasmineUnderTest.MatchersUtil)); expect(shim).toEqual(jasmine.any(jasmineUnderTest.MatchersUtil));
@@ -809,10 +821,11 @@ describe("matchersUtil", function() {
}, },
actual = {x: 42}, actual = {x: 42},
expected = {x: tester}, 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(); }); 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.setRoots).toHaveBeenCalledWith(actual, expected);
expect(diffBuilder.withPath).toHaveBeenCalledWith('x', jasmine.any(Function)); expect(diffBuilder.withPath).toHaveBeenCalledWith('x', jasmine.any(Function));
@@ -825,9 +838,11 @@ describe("matchersUtil", function() {
}, },
actual = {x: 42}, actual = {x: 42},
expected = {x: tester}, 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(); }); 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.setRoots).toHaveBeenCalledWith(actual, expected);
expect(diffBuilder.withPath).toHaveBeenCalledWith('x', jasmine.any(Function)); 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() { it('uses a diffBuilder if one is provided as the fourth argument', function() {
// TODO: remove this in the next major release. // TODO: remove this in the next major release.
var diffBuilder = new jasmineUnderTest.DiffBuilder(), var diffBuilder = new jasmineUnderTest.DiffBuilder(),
matchersUtil = new jasmineUnderTest.MatchersUtil(); matchersUtil = new jasmineUnderTest.MatchersUtil();
spyOn(jasmineUnderTest.getEnv(), 'deprecated'); // suppress warning
spyOn(diffBuilder, 'recordMismatch'); spyOn(diffBuilder, 'recordMismatch');
spyOn(diffBuilder, 'withPath').and.callThrough(); 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() { it("uses custom equality testers if passed to contains and actual is an Array", function() {
// TODO: remove this in the next major release. // TODO: remove this in the next major release.
var customTester = function(a, b) {return true;}, 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(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() { it("uses custom equality testers if passed to the constructor and actual is an Array", function() {
+2 -2
View File
@@ -42,9 +42,9 @@
: 'Expected runnable "' + : 'Expected runnable "' +
fullName + fullName +
'" to have failures ' + '" to have failures ' +
jasmine.pp(expectedFailures) + jasmine.basicPrettyPrinter_(expectedFailures) +
' but it had ' + ' but it had ' +
jasmine.pp(foundFailures) jasmine.basicPrettyPrinter_(foundFailures)
}; };
} }
}; };
+22
View File
@@ -278,6 +278,17 @@ getJasmineRequireObj().Env = function(j$) {
runnableResources[currentRunnable().id].customMatchers; runnableResources[currentRunnable().id].customMatchers;
for (var matcherName in matchersToAdd) { for (var matcherName in matchersToAdd) {
if (matchersToAdd[matcherName].length > 1) {
self.deprecated(
'The matcher factory for "' +
matcherName +
'" ' +
'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.'
);
}
customMatchers[matcherName] = matchersToAdd[matcherName]; customMatchers[matcherName] = matchersToAdd[matcherName];
} }
}; };
@@ -292,6 +303,17 @@ getJasmineRequireObj().Env = function(j$) {
runnableResources[currentRunnable().id].customAsyncMatchers; runnableResources[currentRunnable().id].customAsyncMatchers;
for (var matcherName in matchersToAdd) { for (var matcherName in matchersToAdd) {
if (matchersToAdd[matcherName].length > 1) {
self.deprecated(
'The matcher factory for "' +
matcherName +
'" ' +
'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.'
);
}
customAsyncMatchers[matcherName] = matchersToAdd[matcherName]; customAsyncMatchers[matcherName] = matchersToAdd[matcherName];
} }
}; };
+1 -1
View File
@@ -90,7 +90,7 @@ getJasmineRequireObj().ExceptionFormatter = function(j$) {
} }
if (!empty) { if (!empty) {
return 'error properties: ' + j$.pp(result) + '\n'; return 'error properties: ' + j$.basicPrettyPrinter_(result) + '\n';
} }
return ''; return '';
+1 -1
View File
@@ -164,7 +164,7 @@ getJasmineRequireObj().Spy = function(j$) {
"Spy '" + "Spy '" +
strategyArgs.name + strategyArgs.name +
"' received a call with arguments " + "' received a call with arguments " +
j$.pp(Array.prototype.slice.call(args)) + j$.basicPrettyPrinter_(Array.prototype.slice.call(args)) +
' but all configured strategies specify other arguments.' ' but all configured strategies specify other arguments.'
); );
} else { } else {
@@ -56,10 +56,10 @@ getJasmineRequireObj().asymmetricEqualityTesterArgCompatShim = function(j$) {
i, i,
k; k;
copy(self, customEqualityTesters, 'length'); copyAndDeprecate(self, customEqualityTesters, 'length');
for (i = 0; i < customEqualityTesters.length; i++) { for (i = 0; i < customEqualityTesters.length; i++) {
copy(self, customEqualityTesters, i); copyAndDeprecate(self, customEqualityTesters, i);
} }
var props = arrayProps(); var props = arrayProps();
@@ -67,16 +67,22 @@ getJasmineRequireObj().asymmetricEqualityTesterArgCompatShim = function(j$) {
for (i = 0; i < props.length; i++) { for (i = 0; i < props.length; i++) {
k = props[i]; k = props[i];
if (k !== 'length') { if (k !== 'length') {
copy(self, Array.prototype, k); copyAndDeprecate(self, Array.prototype, k);
} }
} }
return self; return self;
} }
function copy(dest, src, propName) { function copyAndDeprecate(dest, src, propName) {
Object.defineProperty(dest, propName, { Object.defineProperty(dest, propName, {
get: function() { get: function() {
j$.getEnv().deprecated(
'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.'
);
return src[propName]; return src[propName];
} }
}); });
@@ -5,7 +5,7 @@ getJasmineRequireObj().ArrayContaining = function(j$) {
ArrayContaining.prototype.asymmetricMatch = function(other, matchersUtil) { ArrayContaining.prototype.asymmetricMatch = function(other, matchersUtil) {
if (!j$.isArray_(this.sample)) { if (!j$.isArray_(this.sample)) {
throw new Error('You must provide an array to arrayContaining, not ' + j$.pp(this.sample) + '.'); throw new Error('You must provide an array to arrayContaining, not ' + j$.basicPrettyPrinter_(this.sample) + '.');
} }
// If the actual parameter is not an array, we can fail immediately, since it couldn't // If the actual parameter is not an array, we can fail immediately, since it couldn't
@@ -6,7 +6,7 @@ getJasmineRequireObj().ArrayWithExactContents = function(j$) {
ArrayWithExactContents.prototype.asymmetricMatch = function(other, matchersUtil) { ArrayWithExactContents.prototype.asymmetricMatch = function(other, matchersUtil) {
if (!j$.isArray_(this.sample)) { if (!j$.isArray_(this.sample)) {
throw new Error('You must provide an array to arrayWithExactContents, not ' + j$.pp(this.sample) + '.'); throw new Error('You must provide an array to arrayWithExactContents, not ' + j$.basicPrettyPrinter_(this.sample) + '.');
} }
if (this.sample.length !== other.length) { if (this.sample.length !== other.length) {
@@ -1,7 +1,7 @@
getJasmineRequireObj().MapContaining = function(j$) { getJasmineRequireObj().MapContaining = function(j$) {
function MapContaining(sample) { function MapContaining(sample) {
if (!j$.isMap(sample)) { if (!j$.isMap(sample)) {
throw new Error('You must provide a map to `mapContaining`, not ' + j$.pp(sample)); throw new Error('You must provide a map to `mapContaining`, not ' + j$.basicPrettyPrinter_(sample));
} }
this.sample = sample; this.sample = sample;
@@ -1,7 +1,7 @@
getJasmineRequireObj().SetContaining = function(j$) { getJasmineRequireObj().SetContaining = function(j$) {
function SetContaining(sample) { function SetContaining(sample) {
if (!j$.isSet(sample)) { if (!j$.isSet(sample)) {
throw new Error('You must provide a set to `setContaining`, not ' + j$.pp(sample)); throw new Error('You must provide a set to `setContaining`, not ' + j$.basicPrettyPrinter_(sample));
} }
this.sample = sample; this.sample = sample;
+22 -4
View File
@@ -1,6 +1,4 @@
getJasmineRequireObj().MatchersUtil = function(j$) { getJasmineRequireObj().MatchersUtil = function(j$) {
// TODO: convert all uses of j$.pp to use the injected pp
/** /**
* _Note:_ Do not construct this directly. Jasmine will construct one and * _Note:_ Do not construct this directly. Jasmine will construct one and
* pass it to matchers and asymmetric equality testers. * pass it to matchers and asymmetric equality testers.
@@ -30,10 +28,17 @@ getJasmineRequireObj().MatchersUtil = function(j$) {
* @name MatchersUtil#contains * @name MatchersUtil#contains
* @param {*} haystack The collection to search * @param {*} haystack The collection to search
* @param {*} needle The value to search for * @param {*} needle The value to search for
* @param [customTesters] An array of custom equality testers * @param [customTesters] An array of custom equality testers. Deprecated.
* As of 3.6 this parameter no longer needs to be passed. It will be removed in 4.0.
* @returns {boolean} True if `needle` was found in `haystack` * @returns {boolean} True if `needle` was found in `haystack`
*/ */
MatchersUtil.prototype.contains = function(haystack, needle, customTesters) { MatchersUtil.prototype.contains = function(haystack, needle, customTesters) {
if (customTesters) {
j$.getEnv().deprecated('Passing custom equality testers to ' +
'MatchersUtil#contains is deprecated. See ' +
'<https://jasmine.github.io/tutorials/upgrading_to_4.0> for details.');
}
if (j$.isSet(haystack)) { if (j$.isSet(haystack)) {
return haystack.has(needle); return haystack.has(needle);
} }
@@ -122,7 +127,8 @@ getJasmineRequireObj().MatchersUtil = function(j$) {
* @name MatchersUtil#equals * @name MatchersUtil#equals
* @param {*} a The first value to compare * @param {*} a The first value to compare
* @param {*} b The second value to compare * @param {*} b The second value to compare
* @param [customTesters] An array of custom equality testers * @param [customTesters] An array of custom equality testers. Deprecated.
* As of 3.6 this parameter no longer needs to be passed. It will be removed in 4.0.
* @returns {boolean} True if the values are equal * @returns {boolean} True if the values are equal
*/ */
MatchersUtil.prototype.equals = function(a, b, customTestersOrDiffBuilder, diffBuilderOrNothing) { MatchersUtil.prototype.equals = function(a, b, customTestersOrDiffBuilder, diffBuilderOrNothing) {
@@ -131,6 +137,18 @@ getJasmineRequireObj().MatchersUtil = function(j$) {
if (isDiffBuilder(customTestersOrDiffBuilder)) { if (isDiffBuilder(customTestersOrDiffBuilder)) {
diffBuilder = customTestersOrDiffBuilder; diffBuilder = customTestersOrDiffBuilder;
} else { } else {
if (customTestersOrDiffBuilder) {
j$.getEnv().deprecated('Passing custom equality testers to ' +
'MatchersUtil#equals is deprecated. See ' +
'<https://jasmine.github.io/tutorials/upgrading_to_4.0> for details.');
}
if (diffBuilderOrNothing) {
j$.getEnv().deprecated('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.');
}
customTesters = customTestersOrDiffBuilder; customTesters = customTestersOrDiffBuilder;
diffBuilder = diffBuilderOrNothing; diffBuilder = diffBuilderOrNothing;
} }
+26 -3
View File
@@ -55,11 +55,34 @@ var getJasmineRequireObj = (function(jasmineGlobal) {
j$ j$
); );
j$.makePrettyPrinter = jRequire.makePrettyPrinter(j$); j$.makePrettyPrinter = jRequire.makePrettyPrinter(j$);
j$.pp = j$.makePrettyPrinter(); j$.basicPrettyPrinter_ = j$.makePrettyPrinter();
Object.defineProperty(j$, 'pp', {
get: function() {
j$.getEnv().deprecated(
'jasmine.pp is deprecated and will be removed in a future release. ' +
'Use the pp method of the matchersUtil passed to the matcher factory ' +
"or the asymmetric equality tester's `asymmetricMatch` method " +
'instead. See ' +
'<https://jasmine.github.io/tutorials/upgrading_to_4.0> for details.'
);
return j$.basicPrettyPrinter_;
}
});
j$.MatchersUtil = jRequire.MatchersUtil(j$); j$.MatchersUtil = jRequire.MatchersUtil(j$);
j$.matchersUtil = new j$.MatchersUtil({ var staticMatchersUtil = new j$.MatchersUtil({
customTesters: [], customTesters: [],
pp: j$.pp pp: j$.basicPrettyPrinter_
});
Object.defineProperty(j$, 'matchersUtil', {
get: function() {
j$.getEnv().deprecated(
'jasmine.matchersUtil is deprecated and will be removed ' +
'in a future release. Use the instance passed to the matcher factory or ' +
"the asymmetric equality tester's `asymmetricMatch` method instead. " +
'See <https://jasmine.github.io/tutorials/upgrading_to_4.0> for details.'
);
return staticMatchersUtil;
}
}); });
j$.ObjectContaining = jRequire.ObjectContaining(j$); j$.ObjectContaining = jRequire.ObjectContaining(j$);