MCPcopy Index your code
hub / github.com/bendrucker/sinon-as-promised

github.com/bendrucker/sinon-as-promised @v4.0.3

Chat with this repo
repository ↗ · DeepWiki ↗ · release v4.0.3 ↗ · + Follow
3 symbols 4 edges 8 files 0 documented · 0% 1 cross-repo links
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

sinon-as-promised Build Status

Extend Sinon stubs with promise stubbing methods.

Sinon 2 added resolves and rejects methods and no longer requires this library.

Installing

npm install sinon-as-promised

If you're using sinon-as-promised in the browser and are not using Browserify/Webpack, use 3.x or earlier.

Usage

var sinon  = require('sinon')
require('sinon-as-promised')

sinon.stub().resolves('foo')().then(function (value) {
  assert.equal(value, 'foo')
})

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. It defaults to using native ES6 Promise (or provides a polyfill), but you can use another promise library if you'd like, as long as it exposes a constructor:

// Using Bluebird
var Bluebird = require('bluebird')
require('sinon-as-promised')(Bluebird)

API

stub.resolves(value) -> stub

value

Required
Type: any

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(err) -> stub

err

Required
Type: error / string

When called, the stub will return a thenable which will return a reject promise with the provided err. If err 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'
});

Examples

License

MIT © Ben Drucker

Core symbols most depended-on inside this repo

testStub
called by 4
test.js
resolves
called by 0
index.js
rejects
called by 0
index.js

Shape

Function 3

Languages

TypeScript100%

Modules by API surface

index.js2 symbols
test.js1 symbols

Used by 1 indexed graphs manifest dependencies, hub-wide

For agents

$ claude mcp add sinon-as-promised \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact

Ask about this repo answers extend the page