Skip to content

Commit 2430fd9

Browse files
76784mantoni
authored andcommittedApr 3, 2019
Documentation (#2004)
1. replace jQuery.ajax.restore(); with sinon.restore(); 2. improve explanation
1 parent 3812a7d commit 2430fd9

File tree

1 file changed

+3
-6
lines changed

1 file changed

+3
-6
lines changed
 

Diff for: ‎docs/index.md

+3-6
Original file line numberDiff line numberDiff line change
@@ -137,19 +137,16 @@ function getTodos(listId, callback) {
137137
});
138138
}
139139
```
140-
141-
To test this function without triggering network activity we could replace `jQuery.ajax`
140+
A unit test should not actually trigger a function's network activity. To test `getTodos()` without triggering its network activity, use the `sinon.replace()` method to replace the `jQuery.ajax` method in your test. Restore the `jQuery.ajax` method after your test by calling `sinon.restore()` in your test runner's `after()` function.
142141

143142
```javascript
144143
after(function () {
145-
// When the test either fails or passes, restore the original
146-
// jQuery ajax function (Sinon.JS also provides tools to help
147-
// test frameworks automate clean-up like this)
148-
jQuery.ajax.restore();
144+
sinon.restore();
149145
});
150146

151147
it('makes a GET request for todo items', function () {
152148
sinon.replace(jQuery, 'ajax', sinon.fake());
149+
153150
getTodos(42, sinon.fake());
154151

155152
assert(jQuery.ajax.calledWithMatch({ url: '/todo/42/items' }));

0 commit comments

Comments
 (0)