You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardexpand all lines: docs/index.md
-64
Original file line number
Diff line number
Diff line change
@@ -156,67 +156,6 @@ it("makes a GET request for todo items", function () {
156
156
});
157
157
```
158
158
159
-
### Fake XMLHttpRequest
160
-
161
-
While the preceding test shows off some nifty Sinon.JS tricks, it is too tightly coupled to the implementation. When testing Ajax, it is better to use Sinon.JS' [fake XMLHttpRequest][fakexhr]:
162
-
163
-
```javascript
164
-
var xhr, requests;
165
-
166
-
before(function () {
167
-
xhr =sinon.useFakeXMLHttpRequest();
168
-
requests = [];
169
-
xhr.onCreate=function (req) {
170
-
requests.push(req);
171
-
};
172
-
});
173
-
174
-
after(function () {
175
-
// Like before we must clean up when tampering with globals.
176
-
xhr.restore();
177
-
});
178
-
179
-
it("makes a GET request for todo items", function () {
180
-
getTodos(42, sinon.fake());
181
-
182
-
assert.equals(requests.length, 1);
183
-
assert.match(requests[0].url, "/todo/42/items");
184
-
});
185
-
```
186
-
187
-
Learn more about [fake XMLHttpRequest][fakexhr].
188
-
189
-
### Fake server
190
-
191
-
The preceding example shows how flexible this API is. If it looks too laborious, you may like the fake server:
192
-
193
-
```javascript
194
-
var server;
195
-
196
-
before(function () {
197
-
server =sinon.fakeServer.create();
198
-
});
199
-
after(function () {
200
-
server.restore();
201
-
});
202
-
203
-
it("calls callback with deserialized data", function () {
Test framework integration can typically reduce boilerplate further. [Learn more about the fake server][fakeserver].
219
-
220
159
### Faking time
221
160
222
161
> "I don't always bend time and space in unit tests, but when I do, I use Buster.JS + Sinon.JS"
@@ -281,13 +220,10 @@ You've seen the most common tasks people tackle with Sinon.JS, yet we've only sc
281
220
### Sinon.JS elsewhere
282
221
283
222
-[Testing Backbone applications with Jasmine and Sinon](https://tinnedfruit.com/writing/testing-backbone-apps-with-jasmine-sinon.html)
284
-
-[Sinon.JS fake server live demo](https://github.com/ducin/sinon-backend-less-demo)
285
223
286
224
Sinon's "father", Christian Johansen, wrote the book on [Test-Driven JavaScript Development][tddjs], which covers some of the design philosophy and initial sketches for Sinon.JS.
0 commit comments