Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

This file was deleted.

8 changes: 0 additions & 8 deletions docs/release-source/release/mocks.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,14 +77,6 @@ If any expectation is not satisfied, an exception is thrown.

Also restores the mocked methods.

#### `mock.usingPromise(promiseLibrary);`

Causes all expectations created from the mock to return promises using a specific
Promise library instead of the global one when using `expectation.rejects` or
`expectation.resolves`. Returns the mock object to allow chaining.

_Since `sinon@6.2.0`_

### Expectations

All the expectation methods return the expectation, meaning you can chain them.
Expand Down
8 changes: 0 additions & 8 deletions docs/release-source/release/sandbox.md
Original file line number Diff line number Diff line change
Expand Up @@ -303,14 +303,6 @@ Fakes timers and binds the `clock` object to the sandbox such that it too is res

Access through `sandbox.clock`.

#### `sandbox.usingPromise(promiseLibrary);`

Causes all stubs and mocks created from the sandbox to return promises using a specific
Promise library instead of the global one when using `stub.rejects` or
`stub.resolves`. Returns the stub to allow chaining.

_Since `sinon@2.0.0`_

#### `sandbox.restore();`

Restores all fakes created through sandbox.
Expand Down
13 changes: 0 additions & 13 deletions docs/release-source/release/stubs.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ examples:
- stubs-7-call-fake
- stubs-8-call-through
- stubs-9-call-through-with-new
- stubs-10-use-promise-library
- stubs-12-yield-to
- stubs-14-add-behavior
- stubs-15-replace-getter
Expand Down Expand Up @@ -232,7 +231,6 @@ Causes the stub to return a Promise which resolves to the provided value.

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

_Since `sinon@2.0.0`_

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

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

_Since `sinon@2.0.0`_

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

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

#### `stub.usingPromise(promiseLibrary);`

Causes the stub to return promises using a specific Promise library instead of
the global one when using `stub.rejects` or `stub.resolves`. Returns the stub
to allow chaining.

<div data-example-id="stubs-10-use-promise-library"></div>

_Since `sinon@2.0.0`_

#### `stub.yields([arg1, arg2, ...])`

Similar to `callsArg`.
Expand Down
7 changes: 0 additions & 7 deletions lib/sinon/default-behaviors.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,6 @@ const slice = arrayProto.slice;
const useLeftMostCallback = -1;
const useRightMostCallback = -2;

const logger = require("@sinonjs/commons").deprecated;
const wrap = logger.wrap;

function throwsException(fake, error, message) {
if (typeof error === "function") {
fake.exceptionCreator = error;
Expand Down Expand Up @@ -93,10 +90,6 @@ const defaultBehaviors = {
fake.callsThrough = false;
},

usingPromise: wrap(function usingPromise(fake, promiseLibrary) {
fake.promiseLibrary = promiseLibrary;
}, "usingPromise has been deprecated, and will be removed in the next major version"),

yields: function (fake) {
fake.callArgAt = useLeftMostCallback;
fake.callbackArguments = slice(arguments, 1);
Expand Down
24 changes: 2 additions & 22 deletions lib/sinon/fake.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,8 @@
const arrayProto = require("@sinonjs/commons").prototypes.array;
const createProxy = require("./proxy");
const nextTick = require("./util/core/next-tick");
const logger = require("@sinonjs/commons").deprecated;
const wrap = logger.wrap;

const slice = arrayProto.slice;
let promiseLib = Promise;

module.exports = fake;

Expand Down Expand Up @@ -121,7 +118,7 @@ fake.throws = function throws(value) {
fake.resolves = function resolves(value) {
// eslint-disable-next-line jsdoc/require-jsdoc
function f() {
return promiseLib.resolve(value);
return Promise.resolve(value);
}

return wrapFunc(f);
Expand Down Expand Up @@ -149,29 +146,12 @@ fake.resolves = function resolves(value) {
fake.rejects = function rejects(value) {
// eslint-disable-next-line jsdoc/require-jsdoc
function f() {
return promiseLib.reject(getError(value));
return Promise.reject(getError(value));
}

return wrapFunc(f);
};

/**
* Causes `fake` to use a custom Promise implementation, instead of the native
* Promise implementation.
*
* @example
* const bluebird = require("bluebird");
* sinon.fake.usingPromise(bluebird);
*
* @memberof fake
* @param {*} promiseLibrary
* @returns {Function}
*/
fake.usingPromise = wrap(function usingPromise(promiseLibrary) {
promiseLib = promiseLibrary;
return fake;
}, "usingPromise has been deprecated, and will be removed in the next major version");

/**
* Returns a `fake` that calls the callback with the defined arguments.
*
Expand Down
11 changes: 0 additions & 11 deletions lib/sinon/mock.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ const proxyCallToString = require("./proxy-call").toString;
const extend = require("./util/core/extend");
const deepEqual = require("@sinonjs/samsam").deepEqual;
const wrapMethod = require("./util/core/wrap-method");
const usePromiseLibrary = require("./util/core/use-promise-library");

const concat = arrayProto.concat;
const filter = arrayProto.filter;
Expand All @@ -17,9 +16,6 @@ const push = arrayProto.push;
const slice = arrayProto.slice;
const unshift = arrayProto.unshift;

const logger = require("@sinonjs/commons").deprecated;
const wrap = logger.wrap;

function mock(object) {
if (!object || typeof object === "string") {
return mockExpectation.create(object ? object : "Anonymous mock");
Expand Down Expand Up @@ -81,7 +77,6 @@ extend(mock, {
const expectation = mockExpectation.create(method);
expectation.wrappedMethod = this.object[method].wrappedMethod;
push(this.expectations[method], expectation);
usePromiseLibrary(this.promiseLibrary, expectation);

return expectation;
},
Expand Down Expand Up @@ -122,12 +117,6 @@ extend(mock, {
return true;
},

usingPromise: wrap(function usingPromise(promiseLibrary) {
this.promiseLibrary = promiseLibrary;

return this;
}, "usingPromise has been deprecated, and will be removed in the next major version"),

invokeMethod: function invokeMethod(method, thisValue, args) {
/* if we cannot find any matching files we will explicitly call mockExpection#fail with error messages */
/* eslint consistent-return: "off" */
Expand Down
22 changes: 0 additions & 22 deletions lib/sinon/sandbox.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

const arrayProto = require("@sinonjs/commons").prototypes.array;
const logger = require("@sinonjs/commons").deprecated;
const wrap = logger.wrap;
const collectOwnMethods = require("./collect-own-methods");
const getPropertyDescriptor = require("./util/core/get-property-descriptor");
const isPropertyConfigurable = require("./util/core/is-property-configurable");
Expand All @@ -15,7 +14,6 @@ const sinonStub = require("./stub");
const sinonCreateStubInstance = require("./create-stub-instance");
const sinonFake = require("./fake");
const valueToString = require("@sinonjs/commons").valueToString;
const usePromiseLibrary = require("./util/core/use-promise-library");

const DEFAULT_LEAK_THRESHOLD = 10000;

Expand Down Expand Up @@ -79,7 +77,6 @@ function Sandbox(opts = {}) {
const sandbox = this;
const assertOptions = opts.assertOptions || {};
let fakeRestorers = [];
let promiseLib;

let collection = [];
let loggedLeakWarning = false;
Expand Down Expand Up @@ -114,8 +111,6 @@ function Sandbox(opts = {}) {
addToCollection(method);
});

usePromiseLibrary(promiseLib, ownMethods);

return stubbed;
};

Expand Down Expand Up @@ -169,7 +164,6 @@ function Sandbox(opts = {}) {
const m = sinonMock.apply(null, arguments);

addToCollection(m);
usePromiseLibrary(promiseLib, m);

return m;
};
Expand Down Expand Up @@ -422,16 +416,12 @@ function Sandbox(opts = {}) {
forEach(ownMethods, function (method) {
addToCollection(method);
});

usePromiseLibrary(promiseLib, ownMethods);
} else if (Array.isArray(types)) {
for (const accessorType of types) {
addToCollection(spy[accessorType]);
usePromiseLibrary(promiseLib, spy[accessorType]);
}
} else {
addToCollection(spy);
usePromiseLibrary(promiseLib, spy);
}

return spy;
Expand Down Expand Up @@ -497,18 +487,6 @@ function Sandbox(opts = {}) {
throw exception;
}
};

function usingPromise(promiseLibrary) {
promiseLib = promiseLibrary;
collection.promiseLibrary = promiseLibrary;

return sandbox;
}

sandbox.usingPromise = wrap(
usingPromise,
"usingPromise has been deprecated, and will be removed in the next major version",
);
}

Sandbox.prototype.match = match;
Expand Down
21 changes: 0 additions & 21 deletions lib/sinon/util/core/use-promise-library.js

This file was deleted.

43 changes: 0 additions & 43 deletions test/fake-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -485,47 +485,4 @@ describe("fake", function () {
assert.same(myFake.printf, proxy.printf);
});
});

describe(".usingPromise", function () {
before(requirePromiseSupport);

it("should exist and be a function", function () {
assert(fake.usingPromise);
assert.isFunction(fake.usingPromise);
});

it("should set the promise used by resolve", function () {
const promise = {
resolve: function (value) {
return Promise.resolve(value);
},
};
const object = {};

const myFake = fake.usingPromise(promise).resolves(object);

return myFake().then(function (actual) {
assert.same(actual, object, "Same object resolved");
});
});

it("should set the promise used by reject", function () {
const promise = {
reject: function (err) {
return Promise.reject(err);
},
};
const reason = new Error();

const myFake = fake.usingPromise(promise).rejects(reason);

return myFake()
.then(function () {
referee.fail("this should not resolve");
})
.catch(function (actual) {
assert.same(actual, reason, "Same object resolved");
});
});
});
});
Loading