1 | [![NPM version](https://badge.fury.io/js/karma-sinon-chai.png)](http://badge.fury.io/js/karma-sinon-chai) [![Dependency status](https://david-dm.org/xdissent/karma-chai.png)](https://david-dm.org/kmees/karma-sinon-chai) [![devDependency Status](https://david-dm.org/xdissent/karma-chai/dev-status.png)](https://david-dm.org/kmees/karma-sinon-chai#info=devDependencies)
|
2 |
|
3 | karma-sinon-chai
|
4 | ================
|
5 |
|
6 | * [Sinon](http://sinonjs.org/)
|
7 | * [Chai](http://chaijs.com)
|
8 | * [Sinon-Chai](https://github.com/domenic/sinon-chai)
|
9 |
|
10 | for [Karma](http://karma-runner.github.io)
|
11 |
|
12 | Requirements
|
13 | ------------
|
14 |
|
15 | This Karma plugin requires Karma `>=0.10`
|
16 |
|
17 | Installation
|
18 | ------------
|
19 |
|
20 | Install the module via npm
|
21 |
|
22 | ```sh
|
23 | $ npm install --save-dev karma-sinon-chai
|
24 | ```
|
25 |
|
26 | Add `sinon-chai` to the `frameworks` key in your Karma configuration:
|
27 |
|
28 | ```js
|
29 | module.exports = function(config) {
|
30 | 'use strict';
|
31 | config.set({
|
32 | frameworks: ['mocha', 'sinon-chai'],
|
33 | #...
|
34 | });
|
35 | }
|
36 | ```
|
37 |
|
38 | Usage
|
39 | -----
|
40 |
|
41 | Each of the different Chai assertion suites is available in the tests:
|
42 |
|
43 | ```coffee
|
44 | describe 'karma tests with chai', ->
|
45 |
|
46 | it 'should expose the Chai assert method', ->
|
47 | assert.ok('everything', 'everything is ok');
|
48 |
|
49 | it 'should expose the Chai expect method', ->
|
50 | expect('foo').to.not.equal 'bar'
|
51 |
|
52 | it 'should expose the Chai should property', ->
|
53 | 1.should.not.equal 2
|
54 | should.exist 123
|
55 | ```
|
56 |
|
57 | Sinon and Chai matchers for Sinon are also available:
|
58 |
|
59 | ```coffee
|
60 | describe 'karma tests with sinon', ->
|
61 |
|
62 | it 'can spy on objects', ->
|
63 | foo = bar: ->
|
64 | sinon.spy foo, 'bar'
|
65 |
|
66 | foo.bar 'baz'
|
67 |
|
68 | foo.bar.should.have.been.calledWith 'baz'
|
69 | ```
|