Skip to content

Commit 9189518

Browse files
callumacraeeddyerburgh
authored andcommitted
docs: improved docs for nextTick and thrown errors (vuejs#207)
* Improved docs for nextTick and thrown errors * Fixed linting errors
1 parent dc0a2d8 commit 9189518

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

docs/en/guides/getting-started.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,34 @@ To simplify usage, `vue-test-utils` applies all updates synchronously so you don
110110

111111
*Note: `nextTick` is still necessary when you need to explictly advance the event loop, for operations such as asynchronous callbacks or promise resolution.*
112112

113+
If you do still need to use `nextTick` in your test files, be aware that any errors thrown inside it may not be caught by your test runner as it uses promises internally. There are two approaches to fixing this: either you can set the `done` callback as Vue's global error handler at the start of the test, or you can call `nextTick` without an argument and return it as a promise:
114+
115+
```js
116+
// this will not be caught
117+
it('will time out', (done) => {
118+
Vue.nextTick(() => {
119+
expect(true).toBe(false)
120+
done()
121+
})
122+
})
123+
124+
// the two following tests will work as expected
125+
it('will catch the error using done', (done) => {
126+
Vue.config.errorHandler = done
127+
Vue.nextTick(() => {
128+
expect(true).toBe(false)
129+
done()
130+
})
131+
})
132+
133+
it('will catch the error using a promise', () => {
134+
return Vue.nextTick()
135+
.then(function () {
136+
expect(true).toBe(false)
137+
})
138+
})
139+
```
140+
113141
## What's Next
114142

115143
- Integrate `vue-test-utils` into your project by [choosing a test runner](./choosing-a-test-runner.md).

0 commit comments

Comments
 (0)