Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

sinon-as-promised

Package Overview
Dependencies
Maintainers
1
Versions
18
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

sinon-as-promised

Sugar methods for using sinon.js stubs with promises

  • 0.0.3
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
15K
decreased by-19.62%
Maintainers
1
Weekly downloads
 
Created
Source

sinon-as-promised Build Status NPM version

Sugar methods for using sinon.js stubs with promises.

Getting Started

var sinon           = require('sinon');
var Promise         = require('bluebird');
var sinonAsPromised = require('sinon-as-promised')(Promise);

You can use any promise library you'd like that exposes a constructor. You'll only need to call 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.

Usage

stub.resolves(value)

When called, the stub will return a promise which resolves with the provided value.

stub.resolves('foo')().then(function (value) {
    // value === 'foo'
});
stub.rejects(error)

When called, the stub will return a promise which rejects with the provided error. If error is a string, it will be set as the error message.

stub.rejects(new Error('foo'))().catch(function (error) {
    // error.message === 'foo'
});
stub.rejects('foo')().catch(function (error) {
    // error.message === 'foo'
});

License

MIT

Keywords

FAQs

Package last updated on 07 Mar 2014

Did you know?

Socket

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc