jasmine-sinon

WebJar for jasmine-sinon

License

License

BSD
Categories

Categories

ASM Application Layer Libs Bytecode Manipulation
GroupId

GroupId

org.webjars.npm
ArtifactId

ArtifactId

jasmine-sinon
Last Version

Last Version

0.3.2
Release Date

Release Date

Type

Type

jar
Description

Description

jasmine-sinon
WebJar for jasmine-sinon
Project URL

Project URL

http://webjars.org
Source Code Management

Source Code Management

https://github.com/froots/jasmine-sinon

Download jasmine-sinon

How to add to project

<!-- https://jarcasting.com/artifacts/org.webjars.npm/jasmine-sinon/ -->
<dependency>
    <groupId>org.webjars.npm</groupId>
    <artifactId>jasmine-sinon</artifactId>
    <version>0.3.2</version>
</dependency>
// https://jarcasting.com/artifacts/org.webjars.npm/jasmine-sinon/
implementation 'org.webjars.npm:jasmine-sinon:0.3.2'
// https://jarcasting.com/artifacts/org.webjars.npm/jasmine-sinon/
implementation ("org.webjars.npm:jasmine-sinon:0.3.2")
'org.webjars.npm:jasmine-sinon:jar:0.3.2'
<dependency org="org.webjars.npm" name="jasmine-sinon" rev="0.3.2">
  <artifact name="jasmine-sinon" type="jar" />
</dependency>
@Grapes(
@Grab(group='org.webjars.npm', module='jasmine-sinon', version='0.3.2')
)
libraryDependencies += "org.webjars.npm" % "jasmine-sinon" % "0.3.2"
[org.webjars.npm/jasmine-sinon "0.3.2"]

Dependencies

compile (1)

Group / Artifact Type Version
org.webjars.npm : sinon jar [1.7.1,)

Project Modules

There are no modules declared in this project.

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:

expect(mySinonSpy.calledWith('foo')).toBeTruthy();

you can say:

expect(mySinonSpy).toHaveBeenCalledWith('foo');

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.

Installation

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');
require('jasmine-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.any(Date));
expect(spy).toHaveBeenCalledWith(jasmine.objectContaining({name: 'froots'}))

Contributors

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

Versions

Version
0.3.2