
Security News
Deno 2.2 Improves Dependency Management and Expands Node.js Compatibility
Deno 2.2 enhances Node.js compatibility, improves dependency management, adds OpenTelemetry support, and expands linting and task automation for developers.
sinon-as-promised
Advanced tools
Sugar methods for using sinon.js stubs with promises.
var sinon = require('sinon');
var sinonAsPromised = require('sinon-as-promised');
You'll only need to require sinon-as-promised
once. It attaches the appropriate stubbing functions which will then be available anywhere else you require sinon
. You'll probably want to call it in a setup file that is required before your tests. It defaults to Bluebird, but you can use another promise library if you'd like, as long as it exposes a constructor:
// Using RSVP
var RSVP = require('rsvp');
var sinonAsPromised = require('sinon-as-promised')(RSVP.Promise);
// ES6 promises
var sinonAsPromised = require('sinon-as-promised')(Promise);
stub.resolves(value)
When called, the stub will return a "thenable" object which will return a promise for the provided value
. Any Promises/A+ compliant library will handle this object properly.
var stub = sinon.stub();
stub.resolves('foo');
stub().then(function (value) {
// value === 'foo'
});
stub.onCall(0).resolves('bar')
stub().then(function (value) {
// value === 'bar'
});
stub.rejects(error)
When called, the stub will return a thenable which will return a reject promise with the provided error
. If error
is a string, it will be set as the message on an Error
object.
stub.rejects(new Error('foo'))().catch(function (error) {
// error.message === 'foo'
});
stub.rejects('foo')().catch(function (error) {
// error.message === 'foo'
});
stub.onCall(0).rejects('bar');
stub().catch(function (error) {
// error.message === 'bar'
});
FAQs
Sugar methods for using sinon.js stubs with promises
The npm package sinon-as-promised receives a total of 10,137 weekly downloads. As such, sinon-as-promised popularity was classified as popular.
We found that sinon-as-promised demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Deno 2.2 enhances Node.js compatibility, improves dependency management, adds OpenTelemetry support, and expands linting and task automation for developers.
Security News
React's CRA deprecation announcement sparked community criticism over framework recommendations, leading to quick updates acknowledging build tools like Vite as valid alternatives.
Security News
Ransomware payment rates hit an all-time low in 2024 as law enforcement crackdowns, stronger defenses, and shifting policies make attacks riskier and less profitable.