Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ If you have questions that are not covered by the documentation, you can [check
- Require minimal “integration”
- Easy to embed seamlessly with any testing framework
- Easily fake any interface
- Ship with ready-to-use fakes for XMLHttpRequest, timers and more
- Ship with ready-to-use fakes for timers

## Contribute?

Expand Down
3 changes: 0 additions & 3 deletions docs/_data/external_howtos.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
- title: How to Test NodeJS Apps using Mocha, Chai and SinonJS
url: https://scotch.io/tutorials/how-to-test-nodejs-apps-using-mocha-chai-and-sinonjs

- title: How to test an Ajax request using Sinon's fake XMLHttpRequest
url: https://codeutopia.net/blog/2015/03/21/unit-testing-ajax-requests-with-mocha/

- title: How to stub or mock complex objects, such as DOM objects
url: https://codeutopia.net/blog/2016/05/23/sinon-js-quick-tip-how-to-stubmock-complex-objects-such-as-dom-objects/

Expand Down
64 changes: 0 additions & 64 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -156,67 +156,6 @@ it("makes a GET request for todo items", function () {
});
```

### Fake XMLHttpRequest

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]:

```javascript
var xhr, requests;

before(function () {
xhr = sinon.useFakeXMLHttpRequest();
requests = [];
xhr.onCreate = function (req) {
requests.push(req);
};
});

after(function () {
// Like before we must clean up when tampering with globals.
xhr.restore();
});

it("makes a GET request for todo items", function () {
getTodos(42, sinon.fake());

assert.equals(requests.length, 1);
assert.match(requests[0].url, "/todo/42/items");
});
```

Learn more about [fake XMLHttpRequest][fakexhr].

### Fake server

The preceding example shows how flexible this API is. If it looks too laborious, you may like the fake server:

```javascript
var server;

before(function () {
server = sinon.fakeServer.create();
});
after(function () {
server.restore();
});

it("calls callback with deserialized data", function () {
var callback = sinon.fake();
getTodos(42, callback);

// This is part of the FakeXMLHttpRequest API
server.requests[0].respond(
200,
{ "Content-Type": "application/json" },
JSON.stringify([{ id: 1, text: "Provide examples", done: true }]),
);

assert(callback.calledOnce);
});
```

Test framework integration can typically reduce boilerplate further. [Learn more about the fake server][fakeserver].

### Faking time

> "I don't always bend time and space in unit tests, but when I do, I use Buster.JS + Sinon.JS"
Expand Down Expand Up @@ -281,13 +220,10 @@ You've seen the most common tasks people tackle with Sinon.JS, yet we've only sc
### Sinon.JS elsewhere

- [Testing Backbone applications with Jasmine and Sinon](https://tinnedfruit.com/writing/testing-backbone-apps-with-jasmine-sinon.html)
- [Sinon.JS fake server live demo](https://github.com/ducin/sinon-backend-less-demo)

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.

[fakes]: /releases/v{{current_major}}/fakes
[fakexhr]: /releases/v{{current_major}}/fake-xhr-and-server
[fakeserver]: /releases/v{{current_major}}/fake-xhr-and-server#fake-server
[clock]: /releases/v{{current_major}}/fake-timers
[api-docs]: /releases/v{{current_major}}
[tddjs]: https://www.oreilly.com/library/view/test-driven-javascript-development/9780321684097/
1 change: 0 additions & 1 deletion docs/release-source/release.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ This page contains the entire Sinon.JS API documentation along with brief introd
- [Spy calls](./spy-call)
- [Promises](./promises)
- [Fake timers](./fake-timers)
- [Fake <code>XHR</code> and server](./fake-xhr-and-server)
- [JSON-P](./json-p)
- [Assertions](./assertions)
- [Matchers](./matchers)
Expand Down
Loading