Skip to content

Commit 67d19ff

Browse files
authored
chore: deprecate usingPromise (#2651)
1 parent 9e3d58f commit 67d19ff

File tree

4 files changed

+21
-8
lines changed

4 files changed

+21
-8
lines changed

lib/sinon/default-behaviors.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ const slice = arrayProto.slice;
1010
const useLeftMostCallback = -1;
1111
const useRightMostCallback = -2;
1212

13+
const logger = require("@sinonjs/commons").deprecated;
14+
const wrap = logger.wrap;
15+
1316
function throwsException(fake, error, message) {
1417
if (typeof error === "function") {
1518
fake.exceptionCreator = error;
@@ -90,9 +93,9 @@ const defaultBehaviors = {
9093
fake.callsThrough = false;
9194
},
9295

93-
usingPromise: function usingPromise(fake, promiseLibrary) {
96+
usingPromise: wrap(function usingPromise(fake, promiseLibrary) {
9497
fake.promiseLibrary = promiseLibrary;
95-
},
98+
}, "usingPromise has been deprecated, and will be removed in the next major version"),
9699

97100
yields: function (fake) {
98101
fake.callArgAt = useLeftMostCallback;

lib/sinon/fake.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
const arrayProto = require("@sinonjs/commons").prototypes.array;
44
const createProxy = require("./proxy");
55
const nextTick = require("./util/core/next-tick");
6+
const logger = require("@sinonjs/commons").deprecated;
7+
const wrap = logger.wrap;
68

79
const slice = arrayProto.slice;
810
let promiseLib = Promise;
@@ -165,10 +167,10 @@ fake.rejects = function rejects(value) {
165167
* @param {*} promiseLibrary
166168
* @returns {Function}
167169
*/
168-
fake.usingPromise = function usingPromise(promiseLibrary) {
170+
fake.usingPromise = wrap(function usingPromise(promiseLibrary) {
169171
promiseLib = promiseLibrary;
170172
return fake;
171-
};
173+
}, "usingPromise has been deprecated, and will be removed in the next major version");
172174

173175
/**
174176
* Returns a `fake` that calls the callback with the defined arguments.

lib/sinon/mock.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ const push = arrayProto.push;
1717
const slice = arrayProto.slice;
1818
const unshift = arrayProto.unshift;
1919

20+
const logger = require("@sinonjs/commons").deprecated;
21+
const wrap = logger.wrap;
22+
2023
function mock(object) {
2124
if (!object || typeof object === "string") {
2225
return mockExpectation.create(object ? object : "Anonymous mock");
@@ -119,11 +122,11 @@ extend(mock, {
119122
return true;
120123
},
121124

122-
usingPromise: function usingPromise(promiseLibrary) {
125+
usingPromise: wrap(function usingPromise(promiseLibrary) {
123126
this.promiseLibrary = promiseLibrary;
124127

125128
return this;
126-
},
129+
}, "usingPromise has been deprecated, and will be removed in the next major version"),
127130

128131
invokeMethod: function invokeMethod(method, thisValue, args) {
129132
/* if we cannot find any matching files we will explicitly call mockExpection#fail with error messages */

lib/sinon/sandbox.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -536,12 +536,17 @@ function Sandbox(opts = {}) {
536536
"useFakeXMLHttpRequest has been deprecated, and will be removed in the next major version",
537537
);
538538

539-
sandbox.usingPromise = function usingPromise(promiseLibrary) {
539+
function usingPromise(promiseLibrary) {
540540
promiseLib = promiseLibrary;
541541
collection.promiseLibrary = promiseLibrary;
542542

543543
return sandbox;
544-
};
544+
}
545+
546+
sandbox.usingPromise = wrap(
547+
usingPromise,
548+
"usingPromise has been deprecated, and will be removed in the next major version",
549+
);
545550
}
546551

547552
Sandbox.prototype.match = match;

0 commit comments

Comments
 (0)