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:
committed by
Steve Gravrock
parent
258d55469e
commit
90d6f9d73c
@@ -278,6 +278,17 @@ getJasmineRequireObj().Env = function(j$) {
|
||||
runnableResources[currentRunnable().id].customMatchers;
|
||||
|
||||
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];
|
||||
}
|
||||
};
|
||||
@@ -292,6 +303,17 @@ getJasmineRequireObj().Env = function(j$) {
|
||||
runnableResources[currentRunnable().id].customAsyncMatchers;
|
||||
|
||||
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];
|
||||
}
|
||||
};
|
||||
|
||||
@@ -90,7 +90,7 @@ getJasmineRequireObj().ExceptionFormatter = function(j$) {
|
||||
}
|
||||
|
||||
if (!empty) {
|
||||
return 'error properties: ' + j$.pp(result) + '\n';
|
||||
return 'error properties: ' + j$.basicPrettyPrinter_(result) + '\n';
|
||||
}
|
||||
|
||||
return '';
|
||||
|
||||
@@ -164,7 +164,7 @@ getJasmineRequireObj().Spy = function(j$) {
|
||||
"Spy '" +
|
||||
strategyArgs.name +
|
||||
"' 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.'
|
||||
);
|
||||
} else {
|
||||
|
||||
@@ -56,10 +56,10 @@ getJasmineRequireObj().asymmetricEqualityTesterArgCompatShim = function(j$) {
|
||||
i,
|
||||
k;
|
||||
|
||||
copy(self, customEqualityTesters, 'length');
|
||||
copyAndDeprecate(self, customEqualityTesters, 'length');
|
||||
|
||||
for (i = 0; i < customEqualityTesters.length; i++) {
|
||||
copy(self, customEqualityTesters, i);
|
||||
copyAndDeprecate(self, customEqualityTesters, i);
|
||||
}
|
||||
|
||||
var props = arrayProps();
|
||||
@@ -67,16 +67,22 @@ getJasmineRequireObj().asymmetricEqualityTesterArgCompatShim = function(j$) {
|
||||
for (i = 0; i < props.length; i++) {
|
||||
k = props[i];
|
||||
if (k !== 'length') {
|
||||
copy(self, Array.prototype, k);
|
||||
copyAndDeprecate(self, Array.prototype, k);
|
||||
}
|
||||
}
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
function copy(dest, src, propName) {
|
||||
function copyAndDeprecate(dest, src, propName) {
|
||||
Object.defineProperty(dest, propName, {
|
||||
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];
|
||||
}
|
||||
});
|
||||
|
||||
@@ -5,7 +5,7 @@ getJasmineRequireObj().ArrayContaining = function(j$) {
|
||||
|
||||
ArrayContaining.prototype.asymmetricMatch = function(other, matchersUtil) {
|
||||
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
|
||||
|
||||
@@ -6,7 +6,7 @@ getJasmineRequireObj().ArrayWithExactContents = function(j$) {
|
||||
|
||||
ArrayWithExactContents.prototype.asymmetricMatch = function(other, matchersUtil) {
|
||||
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) {
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
getJasmineRequireObj().MapContaining = function(j$) {
|
||||
function MapContaining(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;
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
getJasmineRequireObj().SetContaining = function(j$) {
|
||||
function SetContaining(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;
|
||||
|
||||
@@ -1,6 +1,4 @@
|
||||
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
|
||||
* pass it to matchers and asymmetric equality testers.
|
||||
@@ -30,10 +28,17 @@ getJasmineRequireObj().MatchersUtil = function(j$) {
|
||||
* @name MatchersUtil#contains
|
||||
* @param {*} haystack The collection to search
|
||||
* @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`
|
||||
*/
|
||||
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)) {
|
||||
return haystack.has(needle);
|
||||
}
|
||||
@@ -122,7 +127,8 @@ getJasmineRequireObj().MatchersUtil = function(j$) {
|
||||
* @name MatchersUtil#equals
|
||||
* @param {*} a The first 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
|
||||
*/
|
||||
MatchersUtil.prototype.equals = function(a, b, customTestersOrDiffBuilder, diffBuilderOrNothing) {
|
||||
@@ -131,6 +137,18 @@ getJasmineRequireObj().MatchersUtil = function(j$) {
|
||||
if (isDiffBuilder(customTestersOrDiffBuilder)) {
|
||||
diffBuilder = customTestersOrDiffBuilder;
|
||||
} 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;
|
||||
diffBuilder = diffBuilderOrNothing;
|
||||
}
|
||||
|
||||
@@ -55,11 +55,34 @@ var getJasmineRequireObj = (function(jasmineGlobal) {
|
||||
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 = new j$.MatchersUtil({
|
||||
var staticMatchersUtil = new j$.MatchersUtil({
|
||||
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$);
|
||||
|
||||
Reference in New Issue
Block a user