Skip to content

Commit a1cf658

Browse files
committed
chore!: remove usingPromise
Everyone should be using native promises by now, or should know how to stub natives
1 parent 7af1d23 commit a1cf658

File tree

14 files changed

+2
-416
lines changed

14 files changed

+2
-416
lines changed

docs/release-source/release/examples/stubs-10-use-promise-library.test.js

Lines changed: 0 additions & 18 deletions
This file was deleted.

docs/release-source/release/mocks.md

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -77,14 +77,6 @@ If any expectation is not satisfied, an exception is thrown.
7777

7878
Also restores the mocked methods.
7979

80-
#### `mock.usingPromise(promiseLibrary);`
81-
82-
Causes all expectations created from the mock to return promises using a specific
83-
Promise library instead of the global one when using `expectation.rejects` or
84-
`expectation.resolves`. Returns the mock object to allow chaining.
85-
86-
_Since `sinon@6.2.0`_
87-
8880
### Expectations
8981

9082
All the expectation methods return the expectation, meaning you can chain them.

docs/release-source/release/sandbox.md

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -332,14 +332,6 @@ Fakes XHR and binds a server object to the sandbox such that it too is restored
332332

333333
Access requests through `sandbox.requests` and server through `sandbox.server`
334334

335-
#### `sandbox.usingPromise(promiseLibrary);`
336-
337-
Causes all stubs and mocks created from the sandbox to return promises using a specific
338-
Promise library instead of the global one when using `stub.rejects` or
339-
`stub.resolves`. Returns the stub to allow chaining.
340-
341-
_Since `sinon@2.0.0`_
342-
343335
#### `sandbox.restore();`
344336

345337
Restores all fakes created through sandbox.

docs/release-source/release/stubs.md

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ examples:
1212
- stubs-7-call-fake
1313
- stubs-8-call-through
1414
- stubs-9-call-through-with-new
15-
- stubs-10-use-promise-library
1615
- stubs-12-yield-to
1716
- stubs-14-add-behavior
1817
- stubs-15-replace-getter
@@ -232,7 +231,6 @@ Causes the stub to return a Promise which resolves to the provided value.
232231

233232
When constructing the Promise, sinon uses the `Promise.resolve` method. You are
234233
responsible for providing a polyfill in environments which do not provide `Promise`.
235-
The Promise library can be overwritten using the `usingPromise` method.
236234

237235
_Since `sinon@2.0.0`_
238236

@@ -283,7 +281,6 @@ Causes the stub to return a Promise which rejects with an exception (`Error`).
283281

284282
When constructing the Promise, sinon uses the `Promise.reject` method. You are
285283
responsible for providing a polyfill in environments which do not provide `Promise`.
286-
The Promise library can be overwritten using the `usingPromise` method.
287284

288285
_Since `sinon@2.0.0`_
289286

@@ -332,16 +329,6 @@ Like `callsArg`, but with arguments to pass to the callback.
332329

333330
Like above but with an additional parameter to pass the `this` context.
334331

335-
#### `stub.usingPromise(promiseLibrary);`
336-
337-
Causes the stub to return promises using a specific Promise library instead of
338-
the global one when using `stub.rejects` or `stub.resolves`. Returns the stub
339-
to allow chaining.
340-
341-
<div data-example-id="stubs-10-use-promise-library"></div>
342-
343-
_Since `sinon@2.0.0`_
344-
345332
#### `stub.yields([arg1, arg2, ...])`
346333

347334
Similar to `callsArg`.

lib/sinon/default-behaviors.js

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -90,10 +90,6 @@ const defaultBehaviors = {
9090
fake.callsThrough = false;
9191
},
9292

93-
usingPromise: function usingPromise(fake, promiseLibrary) {
94-
fake.promiseLibrary = promiseLibrary;
95-
},
96-
9793
yields: function (fake) {
9894
fake.callArgAt = useLeftMostCallback;
9995
fake.callbackArguments = slice(arguments, 1);

lib/sinon/fake.js

Lines changed: 2 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ const createProxy = require("./proxy");
55
const nextTick = require("./util/core/next-tick");
66

77
const slice = arrayProto.slice;
8-
let promiseLib = Promise;
98

109
module.exports = fake;
1110

@@ -119,7 +118,7 @@ fake.throws = function throws(value) {
119118
fake.resolves = function resolves(value) {
120119
// eslint-disable-next-line jsdoc/require-jsdoc
121120
function f() {
122-
return promiseLib.resolve(value);
121+
return Promise.resolve(value);
123122
}
124123

125124
return wrapFunc(f);
@@ -147,29 +146,12 @@ fake.resolves = function resolves(value) {
147146
fake.rejects = function rejects(value) {
148147
// eslint-disable-next-line jsdoc/require-jsdoc
149148
function f() {
150-
return promiseLib.reject(getError(value));
149+
return Promise.reject(getError(value));
151150
}
152151

153152
return wrapFunc(f);
154153
};
155154

156-
/**
157-
* Causes `fake` to use a custom Promise implementation, instead of the native
158-
* Promise implementation.
159-
*
160-
* @example
161-
* const bluebird = require("bluebird");
162-
* sinon.fake.usingPromise(bluebird);
163-
*
164-
* @memberof fake
165-
* @param {*} promiseLibrary
166-
* @returns {Function}
167-
*/
168-
fake.usingPromise = function usingPromise(promiseLibrary) {
169-
promiseLib = promiseLibrary;
170-
return fake;
171-
};
172-
173155
/**
174156
* Returns a `fake` that calls the callback with the defined arguments.
175157
*

lib/sinon/mock.js

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ const proxyCallToString = require("./proxy-call").toString;
66
const extend = require("./util/core/extend");
77
const deepEqual = require("@sinonjs/samsam").deepEqual;
88
const wrapMethod = require("./util/core/wrap-method");
9-
const usePromiseLibrary = require("./util/core/use-promise-library");
109

1110
const concat = arrayProto.concat;
1211
const filter = arrayProto.filter;
@@ -78,7 +77,6 @@ extend(mock, {
7877
const expectation = mockExpectation.create(method);
7978
expectation.wrappedMethod = this.object[method].wrappedMethod;
8079
push(this.expectations[method], expectation);
81-
usePromiseLibrary(this.promiseLibrary, expectation);
8280

8381
return expectation;
8482
},
@@ -119,12 +117,6 @@ extend(mock, {
119117
return true;
120118
},
121119

122-
usingPromise: function usingPromise(promiseLibrary) {
123-
this.promiseLibrary = promiseLibrary;
124-
125-
return this;
126-
},
127-
128120
invokeMethod: function invokeMethod(method, thisValue, args) {
129121
/* if we cannot find any matching files we will explicitly call mockExpection#fail with error messages */
130122
/* eslint consistent-return: "off" */

lib/sinon/sandbox.js

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ const sinonFake = require("./fake");
1616
const valueToString = require("@sinonjs/commons").valueToString;
1717
const fakeServer = require("nise").fakeServer;
1818
const fakeXhr = require("nise").fakeXhr;
19-
const usePromiseLibrary = require("./util/core/use-promise-library");
2019

2120
const DEFAULT_LEAK_THRESHOLD = 10000;
2221

@@ -80,7 +79,6 @@ function Sandbox(opts = {}) {
8079
const sandbox = this;
8180
const assertOptions = opts.assertOptions || {};
8281
let fakeRestorers = [];
83-
let promiseLib;
8482

8583
let collection = [];
8684
let loggedLeakWarning = false;
@@ -117,8 +115,6 @@ function Sandbox(opts = {}) {
117115
addToCollection(method);
118116
});
119117

120-
usePromiseLibrary(promiseLib, ownMethods);
121-
122118
return stubbed;
123119
};
124120

@@ -177,7 +173,6 @@ function Sandbox(opts = {}) {
177173
const m = sinonMock.apply(null, arguments);
178174

179175
addToCollection(m);
180-
usePromiseLibrary(promiseLib, m);
181176

182177
return m;
183178
};
@@ -430,16 +425,12 @@ function Sandbox(opts = {}) {
430425
forEach(ownMethods, function (method) {
431426
addToCollection(method);
432427
});
433-
434-
usePromiseLibrary(promiseLib, ownMethods);
435428
} else if (Array.isArray(types)) {
436429
for (const accessorType of types) {
437430
addToCollection(spy[accessorType]);
438-
usePromiseLibrary(promiseLib, spy[accessorType]);
439431
}
440432
} else {
441433
addToCollection(spy);
442-
usePromiseLibrary(promiseLib, spy);
443434
}
444435

445436
return spy;
@@ -524,13 +515,6 @@ function Sandbox(opts = {}) {
524515
addToCollection(xhr);
525516
return xhr;
526517
};
527-
528-
sandbox.usingPromise = function usingPromise(promiseLibrary) {
529-
promiseLib = promiseLibrary;
530-
collection.promiseLibrary = promiseLibrary;
531-
532-
return sandbox;
533-
};
534518
}
535519

536520
Sandbox.prototype.match = match;

lib/sinon/util/core/use-promise-library.js

Lines changed: 0 additions & 21 deletions
This file was deleted.

test/fake-test.js

Lines changed: 0 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -485,47 +485,4 @@ describe("fake", function () {
485485
assert.same(myFake.printf, proxy.printf);
486486
});
487487
});
488-
489-
describe(".usingPromise", function () {
490-
before(requirePromiseSupport);
491-
492-
it("should exist and be a function", function () {
493-
assert(fake.usingPromise);
494-
assert.isFunction(fake.usingPromise);
495-
});
496-
497-
it("should set the promise used by resolve", function () {
498-
const promise = {
499-
resolve: function (value) {
500-
return Promise.resolve(value);
501-
},
502-
};
503-
const object = {};
504-
505-
const myFake = fake.usingPromise(promise).resolves(object);
506-
507-
return myFake().then(function (actual) {
508-
assert.same(actual, object, "Same object resolved");
509-
});
510-
});
511-
512-
it("should set the promise used by reject", function () {
513-
const promise = {
514-
reject: function (err) {
515-
return Promise.reject(err);
516-
},
517-
};
518-
const reason = new Error();
519-
520-
const myFake = fake.usingPromise(promise).rejects(reason);
521-
522-
return myFake()
523-
.then(function () {
524-
referee.fail("this should not resolve");
525-
})
526-
.catch(function (actual) {
527-
assert.same(actual, reason, "Same object resolved");
528-
});
529-
});
530-
});
531488
});

0 commit comments

Comments
 (0)