Skip to content
Go to file

Latest commit


Git stats


Failed to load latest commit information.
Latest commit message
Commit time

Jasmine matchers for Sinon.JS

Build Status

jasmine-sinon provides a set of custom matchers for using the Sinon.JS spying, stubbing and mocking library with Jasmine BDD.

Instead of:


you can say:


This is not only nicerer to look at in your purdy specs, but you get more descriptive failure output in your Jasmine spec runner.

Instead of:

Expected false to be truthy.

you get:

Expected spy "mySpy" to have been called with "foo".

Jasmine 1.x / 2.x compatibility

If you are using Jasmine 1.x, use the latest 0.3.x release. For Jasmine 2, use 0.4 or above.


Direct include

Just include lib/jasmine-sinon.js in your Jasmine test runner file. Don't forget to include sinon.js.

With jasmine-gem

Add it to jasmine.yml. Don't forget to include sinon.js.

Node.js / NPM

npm install jasmine-sinon --save-dev

Then, in your jasmine spec:

var sinon = require('sinon');

Using Bower

bower install jasmine-sinon --save-dev

Then, include components/jasmine-sinon/index.js in your test runner.

Sinon.JS matchers

In general, you should be able to translate a Sinon spy/stub/mock API method to a jasmine-sinon matcher by prepending toHaveBeen to the front of the method name. For example, the Sinon.JS spy method called becomes toHaveBeenCalled. There are one or two exceptions to this rule, so the full list of matchers is given below.

Sinon.JS property / method jasmine-sinon matcher
called toHaveBeenCalled()
calledOnce toHaveBeenCalledOnce()
calledTwice toHaveBeenCalledTwice()
calledThrice toHaveBeenCalledThrice()
calledBefore() toHaveBeenCalledBefore()
calledAfter() toHaveBeenCalledAfter()
calledOn() toHaveBeenCalledOn()
alwaysCalledOn() toHaveBeenAlwaysCalledOn()
calledWith() toHaveBeenCalledWith()
alwaysCalledWith() toHaveBeenAlwaysCalledWith()
calledWithExactly() toHaveBeenCalledWithExactly()
alwaysCalledWithExactly() toHaveBeenAlwaysCalledWithExactly()
calledWithMatch() toHaveBeenCalledWithMatch()
alwaysCalledWithMatch() toHaveBeenAlwaysCalledWithMatch()
calledWithNew toHaveBeenCalledWithNew() >=v0.4
neverCalledWith toHaveBeenNeverCalledWith() >=v0.4
neverCalledWithMatch() toHaveBeenNeverCalledWithMatch() >=v0.4
threw() toHaveThrown()
alwaysThrew() toHaveAlwaysThrown()
returned() toHaveReturned()
alwaysReturned() toHaveAlwaysReturned()

These matchers will work on spies, individual spy calls, stubs and mocks.

You can use Jasmine spies alongside your Sinon spies. jasmine-sinon will detect which you're using and use the appropriate matcher.

You can also use Jasmine's fuzzy matchers any() and objectContaining() in expectations, e.g.

expect(spy).toHaveBeenCalledWith(jasmine.objectContaining({name: 'froots'}))


Thanks to:

  • @aelesbao for Exception matchers
  • @theinterned for, er, match matchers
  • @milichev for graceful spy matchers
  • @reinseth for Jasmine fuzzy matcher support
  • @stoodder for initial Jasmine 2.0 support work
You can’t perform that action at this time.