8000 from Dos through Assert console.error section · mcibique/vue-testing-examples@2e6b0d5 · GitHub
[go: up one dir, main page]

Skip to content

Commit 2e6b0d5

Browse files
committed
from Dos through Assert console.error section
1 parent 1d35099 commit 2e6b0d5

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ it('should call external API with given params', function () {
144144

145145
### Dos
146146

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.
148148
* 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`.
149149
* Always restore axios back to the state before your test was running. Use `axios.restore()` function to do so.
150150
* 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
182182

183183
## Assert console.error() has not been called
184184

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()`.
186186

187187
```js
188188
import sinon from 'sinon';
@@ -192,7 +192,7 @@ beforeEach(function () {
192192
if (console.error.restore) { // <- check whether the spy isn't already attached
193193
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)
194194
}
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
196196
});
197197

198198
afterEach(function () {

0 commit comments

Comments
 (0)
0