OSDN Git Service

Regular updates
[twpd/master.git] / sinon-chai.md
1 ---
2 title: Sinon-chai
3 category: JavaScript libraries
4 layout: default-ad
5 ---
6
7   * [Sinon-chai](https://github.com/domenic/sinon-chai)
8
9
10 ### Initialization
11
12 ```js
13 var sinon = require('sinon');
14 require('chai').use(require('sinon-chai'));
15 ```
16
17 ### Assert
18
19     expect(spy).called
20     expect(spy).calledOnce
21     expect(spy).calledTwice
22     expect(spy).calledThrice
23     expect(spy).calledBefore
24     expect(spy).calledAfter
25     expect(spy).calledWithNew
26     expect(spy).alwaysCalledWithNew
27     expect(spy).calledOn
28     expect(spy).alwaysCalledOn
29     expect(spy).calledWith
30     expect(spy).alwaysCalledWith
31     expect(spy).calledWithExactly
32     expect(spy).alwaysCalledWithExactly
33     expect(spy).calledWithMatch
34     expect(spy).alwaysCalledWithMatch
35     expect(spy).returned
36     expect(spy).alwaysReturned
37     expect(spy).threw
38     expect(spy).alwaysThrew
39
40 ### Should
41
42     spy.should.have.been.called
43     spy.should.have.been.calledOnce
44     spy.should.have.been.calledTwice
45     spy.should.have.been.calledThrice
46     spy1.should.have.been.calledBefore(spy2)
47     spy1.should.have.been.calledAfter(spy2)
48     spy.should.have.been.calledWithNew
49     spy.should.always.have.been.calledWithNew
50     spy.should.have.been.calledOn(context)
51     spy.should.always.have.been.calledOn(context)
52     spy.should.have.been.calledWith(...args)
53     spy.should.always.have.been.calledWith(...args)
54     spy.should.always.have.been.calledWithExactly(...args)
55     spy.should.always.have.been.calledWithExactly(...args)
56     spy.should.have.been.calledWithMatch(...args)
57     spy.should.always.have.been.calledWithMatch(...args)
58     spy.should.have.returned(returnVal)
59     spy.should.have.always.returned(returnVal)
60     spy.should.have.thrown(errorObjOrErrorTypeStringOrNothing)
61     spy.should.have.always.thrown(errorObjOrErrorTypeStringOrNothing)