Skip to content

Commit 95d4b8f

Browse files
committedMar 24, 2025·
chore!: remove fakeXMLHttpRequest and fakeServer
BREAKING CHANGE: remove fakeXMLHttpRequest and fakeServer from the API
1 parent e47cb9d commit 95d4b8f

17 files changed

+10
-996
lines changed
 

‎README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ If you have questions that are not covered by the documentation, you can [check
5555
- Require minimal “integration”
5656
- Easy to embed seamlessly with any testing framework
5757
- Easily fake any interface
58-
- Ship with ready-to-use fakes for XMLHttpRequest, timers and more
58+
- Ship with ready-to-use fakes for timers
5959

6060
## Contribute?
6161

‎docs/_data/external_howtos.yml

-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
- title: How to Test NodeJS Apps using Mocha, Chai and SinonJS
22
url: https://scotch.io/tutorials/how-to-test-nodejs-apps-using-mocha-chai-and-sinonjs
33

4-
- title: How to test an Ajax request using Sinon's fake XMLHttpRequest
5-
url: https://codeutopia.net/blog/2015/03/21/unit-testing-ajax-requests-with-mocha/
6-
74
- title: How to stub or mock complex objects, such as DOM objects
85
url: https://codeutopia.net/blog/2016/05/23/sinon-js-quick-tip-how-to-stubmock-complex-objects-such-as-dom-objects/
96

‎docs/index.md

-64
Original file line numberDiff line numberDiff line change
@@ -156,67 +156,6 @@ it("makes a GET request for todo items", function () {
156156
});
157157
```
158158

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 () {
204-
var callback = sinon.fake();
205-
getTodos(42, callback);
206-
207-
// This is part of the FakeXMLHttpRequest API
208-
server.requests[0].respond(
209-
200,
210-
{ "Content-Type": "application/json" },
211-
JSON.stringify([{ id: 1, text: "Provide examples", done: true }]),
212-
);
213-
214-
assert(callback.calledOnce);
215-
});
216-
```
217-
218-
Test framework integration can typically reduce boilerplate further. [Learn more about the fake server][fakeserver].
219-
220159
### Faking time
221160

222161
> "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
281220
### Sinon.JS elsewhere
282221

283222
- [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)
285223

286224
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.
287225

288226
[fakes]: /releases/v{{current_major}}/fakes
289-
[fakexhr]: /releases/v{{current_major}}/fake-xhr-and-server
290-
[fakeserver]: /releases/v{{current_major}}/fake-xhr-and-server#fake-server
291227
[clock]: /releases/v{{current_major}}/fake-timers
292228
[api-docs]: /releases/v{{current_major}}
293229
[tddjs]: https://www.oreilly.com/library/view/test-driven-javascript-development/9780321684097/

‎docs/release-source/release.md

-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ This page contains the entire Sinon.JS API documentation along with brief introd
1818
- [Spy calls](./spy-call)
1919
- [Promises](./promises)
2020
- [Fake timers](./fake-timers)
21-
- [Fake <code>XHR</code> and server](./fake-xhr-and-server)
2221
- [JSON-P](./json-p)
2322
- [Assertions](./assertions)
2423
- [Matchers](./matchers)

0 commit comments

Comments
 (0)
Please sign in to comment.