Skip to content

Commit 9025610

Browse files
author
Jess
committed
Adding notes about async vs. sync mode. Adding placeholder for mocking transitions section
1 parent 3115396 commit 9025610

File tree

1 file changed

+21
-3
lines changed

1 file changed

+21
-3
lines changed

docs/guides/common-tips.md

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,11 @@ const wrapper = shallowMount(Component)
2727
wrapper.vm // the mounted Vue instance
2828
```
2929

30-
### Using `nextTick`
30+
### Writing asynchronous tests using `nextTick` (new)
3131

32-
Vue batches watcher updates and runs them asynchronously on the "next tick".
32+
By default, Vue batches updates to run asynchronously (on the next "tick"). This is to prevent unnecessary DOM re-renders, and watcher computations ([see the docs](https://vuejs.org/v2/guide/reactivity.html#Async-Update-Queue) for more details).
3333

34-
In practice, this means you must wait for updates to run after you set a reactive property. You can wait for updates with `Vue.nextTick()`:
34+
This means you **must** wait for updates to run after you set a reactive property. You can wait for updates with `Vue.nextTick()`:
3535

3636
```js
3737
it('updates text', async () => {
@@ -40,8 +40,23 @@ it('updates text', async () => {
4040
await Vue.nextTick()
4141
expect(wrapper.text()).toContain('updated')
4242
})
43+
44+
// Or if you're without async/await
45+
it('render text', (done) => {
46+
const wrapper = mount(TestComponent)
47+
wrapper.trigger('click')
48+
Vue.nextTick(() => {
49+
wrapper.text().toContain('some text')
50+
wrapper.trigger('click')
51+
Vue.nextTick(() => {
52+
wrapper.text().toContain('some different text')
53+
done()
54+
})
55+
})
56+
})
4357
```
4458

59+
4560
The following methods often cause watcher updates that require you to wait for the next tick:
4661

4762
- `setChecked`
@@ -160,6 +175,9 @@ You can also update the props of an already-mounted component with the `wrapper.
160175

161176
_For a full list of options, please see the [mount options section](../api/options.md) of the docs._
162177

178+
### Mocking Transitions
179+
180+
163181
### Applying Global Plugins and Mixins
164182

165183
Some of the components may rely on features injected by a global plugin or mixin, for example `vuex` and `vue-router`.

0 commit comments

Comments
 (0)