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