karma-sinon-expect

karma-sinon-expect ================

npm install karma-sinon-expect
3 downloads in the last day
104 downloads in the last week
501 downloads in the last month

karma-sinon-expect

Karma

Build Status

for Karma

This package wrap sinon.assert API to expect.

Installation

Install the module via npm

$ npm install --save-dev karma-sinon-expect

Nodejs

Use sinon and expect from karma-sinon-expect package

global.expect = require('karma-sinon-expect').expect;

Use custom version of sinon and expect

global.expect = require('karma-sinon-expect').use(require('sinon'), require('expect.js'));

Karma

This Karma plugin requires Karma ~0.10.0

Add sinon-expect to the frameworks key in your Karma configuration:

module.exports = function(config) {
  config.set({
    frameworks: ['mocha', 'sinon-expect'],
    ...
  });
}

Browser

Install the module via bower

$ bower install sinon-expect
<script src="bower_components/expect/expect.js" type="text/javascript"></script>
<script src="bower_components/sinonjs/sinon.js" type="text/javascript"></script>
<script src="bower_components/sinon-expect/sinon-expect.js" type="text/javascript"></script>

Usage

Sinon and expect matchers for Sinon are also available:

describe 'karma tests with sinon', ->

  it 'can spy on objects', ->
    foo = bar: ->
    sinon.spy foo, 'bar'

    foo.bar 'baz'

    expect(foo.bar).to.be.calledWith 'baz'

Additional expectation

describe 'tests sinon spy with arguments', ->

  it 'expect first argument', ->
    foo = bar: ->
    sinon.spy foo, 'bar'

    foo.bar 'baz'

    expect(foo.bar).firstArgument().to.be.equal 'baz'

  it 'expect second argument', ->
    foo = bar: ->
    sinon.spy foo, 'bar'

    foo.bar 'baz', 'foo'

    expect(foo.bar).secondArgument().to.be.equal 'foo'

  it 'expect any argument', ->
    foo = bar: ->
    sinon.spy foo, 'bar'

    foo.bar 'baz', 'foo', 'bar'

    expect(foo.bar).argument(2).to.be.equal 'bar'

Conversion table

sinon.assert expect
sinon.assert.calledOnce(spy) expect(spy).to.be.calledOnce()
npm loves you