-
Notifications
You must be signed in to change notification settings - Fork 106
/
Copy pathcallCount.js
193 lines (156 loc) · 5.61 KB
/
callCount.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
import sinon from "sinon";
import { expect, AssertionError } from "chai";
describe("Call count", function () {
var spy = null;
beforeEach(function () {
spy = sinon.spy();
});
describe("called", function () {
it("should throw an assertion error when the spy is undefined", function () {
expect(function () {
expect(undefined).to.have.been.called;
}).to.throw(TypeError);
});
it("should throw an assertion error when the spy is not called", function () {
expect(function () {
spy.should.have.been.called;
}).to.throw(AssertionError);
});
it("should not throw when the spy is called once", function () {
spy();
expect(function () {
spy.should.have.been.called;
}).to.not.throw();
});
it("should not throw when the spy is called twice", function () {
spy();
spy();
expect(function () {
spy.should.have.been.called;
}).to.not.throw();
});
});
describe("not called", function () {
it("should not throw when the spy is not called", function () {
expect(function () {
spy.should.not.have.been.called;
}).to.not.throw();
});
it("should throw an assertion error when the spy is called once", function () {
spy();
expect(function () {
spy.should.not.have.been.called;
}).to.throw(AssertionError);
});
});
describe("callCount", function () {
it("should throw an assertion error when the spy is not called", function () {
expect(function () {
spy.should.have.callCount();
}).to.throw(AssertionError);
});
it("should not throw an assertion error when the number of calls equals provided call count", function () {
spy();
spy();
spy();
spy();
expect(function () {
spy.should.have.callCount(4);
}).to.not.throw(AssertionError);
});
it("should throw an assertion error whenever the number of calls are not equal to provided call count",
function () {
spy();
spy();
spy();
expect(function () {
spy.should.have.callCount(4);
}).to.throw(AssertionError);
});
});
describe("calledOnce", function () {
it("should throw an assertion error when the spy is not called", function () {
expect(function () {
spy.should.have.been.calledOnce;
}).to.throw(AssertionError);
});
it("should not throw when the spy is called once", function () {
spy();
expect(function () {
spy.should.have.been.calledOnce;
}).to.not.throw();
});
it("should throw an assertion error when the spy is called twice", function () {
spy();
spy();
expect(function () {
spy.should.have.been.calledOnce;
}).to.throw(AssertionError);
});
});
describe("calledTwice", function () {
it("should throw an assertion error when the spy is not called", function () {
expect(function () {
spy.should.have.been.calledTwice;
}).to.throw(AssertionError);
});
it("should throw an assertion error when the spy is called once", function () {
spy();
expect(function () {
spy.should.have.been.calledTwice;
}).to.throw(AssertionError);
});
it("should not throw when the spy is called twice", function () {
spy();
spy();
expect(function () {
spy.should.have.been.calledTwice;
}).to.not.throw();
});
it("should throw an assertion error when the spy is called thrice", function () {
spy();
spy();
spy();
expect(function () {
spy.should.have.been.calledTwice;
}).to.throw(AssertionError);
});
});
describe("calledThrice", function () {
it("should throw an assertion error when the spy is not called", function () {
expect(function () {
spy.should.have.been.calledThrice;
}).to.throw(AssertionError);
});
it("should throw an assertion error when the spy is called once", function () {
spy();
expect(function () {
spy.should.have.been.calledThrice;
}).to.throw(AssertionError);
});
it("should throw an assertion error when the spy is called twice", function () {
spy();
spy();
expect(function () {
spy.should.have.been.calledThrice;
}).to.throw(AssertionError);
});
it("should not throw when the spy is called thrice", function () {
spy();
spy();
spy();
expect(function () {
spy.should.have.been.calledThrice;
}).to.not.throw();
});
it("should throw an assertion error when the spy is called four times", function () {
spy();
spy();
spy();
spy();
expect(function () {
spy.should.have.been.calledThrice;
}).to.throw(AssertionError);
});
});
});