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 | # chai config
|
35 | client: {
|
36 | chai: {
|
37 | includeStack: true
|
38 | }
|
39 | }
|
40 |
|
41 | #...
|
42 | });
|
43 | }
|
44 | ```
|
45 |
|
46 | Usage
|
47 | -----
|
48 |
|
49 | Each of the different Chai assertion suites is available in the tests:
|
50 |
|
51 | ```coffee
|
52 | describe 'karma tests with chai', ->
|
53 |
|
54 | it 'should expose the Chai assert method', ->
|
55 | assert.ok('everything', 'everything is ok');
|
56 |
|
57 | it 'should expose the Chai expect method', ->
|
58 | expect('foo').to.not.equal 'bar'
|
59 |
|
60 | it 'should expose the Chai should property', ->
|
61 | 1.should.not.equal 2
|
62 | should.exist 123
|
63 | ```
|
64 |
|
65 | Sinon and Chai matchers for Sinon are also available:
|
66 |
|
67 | ```coffee
|
68 | describe 'karma tests with sinon', ->
|
69 |
|
70 | it 'can spy on objects', ->
|
71 | foo = bar: ->
|
72 | sinon.spy foo, 'bar'
|
73 |
|
74 | foo.bar 'baz'
|
75 |
|
76 | foo.bar.should.have.been.calledWith 'baz'
|
77 | ```
|
78 |
|
79 | Changelog
|
80 | ----------------
|
81 | ### v2.0.0
|
82 | * Removed `lolex` dependency. Please use [Sinon's fake timers](http://sinonjs.org/releases/v4.5.0/fake-timers/) instead, which use `lolex` under the hood.
|
83 |
|
84 | ### v1.1.0
|
85 | * Fixed broken Sinon dependency
|
86 | * Updated depenencies
|
87 | * Chai: `~3.0 => ~3.2.0`
|
88 | * Sinon: `~1.15.0 => ~1.16.0`
|
89 | * Removed `lodash` dependency
|
90 |
|
91 | ### v1.0.0
|
92 | * Updated to broken sinon version. Probably doesnt work :bomb:.
|