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: README.md
+3-3Lines changed: 3 additions & 3 deletions
Original file line number
Diff line number
Diff line change
@@ -144,7 +144,7 @@ it('should call external API with given params', function () {
144
144
145
145
### Dos
146
146
147
-
* When defining mock, always try to set expected params or body (be as much specific as it gets). It prevents your tests going green because of the functionality under test was accidentally called from other parts of your code.
147
+
* When defining mock, always try to set expected params or body (be as much specific as possible). It prevents your tests going green because of the functionality under test was accidentally called from other parts of your code.
148
148
* Always specify the number of calls you expect to happen. Use `replyOnce` when you know the external call should happen only once (99% test cases). If your code has a bug and calls API twice, you will spot the problem because the 2nd call will fail with `Error: Request failed with status code 404`.
149
149
* Always restore axios back to the state before your test was running. Use `axios.restore()` function to do so.
150
150
* Verify after each test that all registered mocks have been called using `axios.verifyNoOutstandingExpectation()`. It can catch issues when your test didn't executed part of the code you expected, but still went green. You can implement your own expectation if you need to, this is the current implementation:
@@ -182,7 +182,7 @@ If you really need to check whether the `get` or `post` have been called, use ra
182
182
183
183
## Assert console.error() has not been called
184
184
185
-
Let's have a test expecting no action to happen (e.g. a disabled button that should not be enabled while an input is empty). The test loads the form and then it checks if the button is disabled. Everything goes green and everybody's happy. But there is a different problem your test didn't cover: the button was not kept disabled because of the application logic, but because of a javascript error somewhere in your code. To catch cases like this, make sure, after each test, that `console.error()` has not been called. You can spy on `error` function and verify expectations in `afterEach()`.
185
+
Let's have a test expecting no action to happen (e.g. a disabled button that should not be enabled while an input is empty). The test loads the form and then it checks if the button is disabled. Everything goes green and everybody's happy. But there is a different problem, your test didn't cover: the button was not kept disabled because of the application logic, but because of a javascript error somewhere in your code. To catch cases like this, make sure, after each test, that `console.error()` has not been called. You can spy on `error` function and verify expectations in `afterEach()`.
186
186
187
187
```js
188
188
importsinonfrom'sinon';
@@ -192,7 +192,7 @@ beforeEach(function () {
192
192
if (console.error.restore) { // <- check whether the spy isn't already attached
193
193
console.error.restore(); // restore it if so. this might happen if previous test crashed the test runner (e.g. Syntax Error in your spec file)
194
194
}
195
-
sinon.spy(console, 'error'); // use only spy so the original functionality is still preserved, don't stub the error function
195
+
sinon.spy(console, 'error'); // use only spy so the original functionality is preserved, don't stub the error function
0 commit comments