Skip to content
Jasmine matchers for Sinon.JS
Find file
New pull request
Pull request Compare This branch is 45 commits behind froots:master.
Fetching latest commit...
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.

Jasmine matchers for Sinon.JS

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 Function to have been called.


Just include jasmine-sinon.js in your Jasmine test runner file, or add it to jasmine.yml if you are using jasmine-gem. Don't forget to include sinon.js.

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()
returned() toHaveReturned()
alwaysReturned() toHaveAlwaysReturned()
threw() toHaveThrown()
alwaysThrew() toHaveAlwaysThrown()

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


jasmine-sinon currently overwrites any Jasmine matchers of the same name used for its own spying features. I plan to allow these to be optionally retained in the future.

The native Jasmine matchers that are overwritten are:

  • toHaveBeenCalled()
  • toHaveBeenCalledWith()


Thanks to:

  • @aelesbao for Exception matchers
  • @theinterned for, er, match matchers
Something went wrong with that request. Please try again.