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
fix: update unit test code examples with Vue Test Utils (#2468)
* fix: update unit test code examples with Vue Test Utils
* fix: use vm. instead of Vue.nextTick to avoid importing Vue
* fix: change name in paragraph
it('renders correctly with different props', () => {
101
-
expect(getRenderedText(MyComponent, {
102
-
msg:'Hello'
103
-
})).toBe('Hello')
104
-
105
-
expect(getRenderedText(MyComponent, {
106
-
msg:'Bye'
107
-
})).toBe('Bye')
101
+
expect(
102
+
getMountedComponent(MyComponent, {
103
+
msg:'Hello'
104
+
}).text()
105
+
).toBe('Hello')
106
+
107
+
expect(
108
+
getMountedComponent(MyComponent, {
109
+
msg:'Bye'
110
+
}).text()
111
+
).toBe('Bye')
108
112
})
109
113
})
110
114
```
111
115
112
116
## Asserting Asynchronous Updates
113
117
114
-
Since Vue [performs DOM updates asynchronously](reactivity.html#Async-Update-Queue), assertions on DOM updates resulting from state change will have to be made in a `Vue.nextTick` callback:
118
+
Since Vue [performs DOM updates asynchronously](reactivity.html#Async-Update-Queue), assertions on DOM updates resulting from state change will have to be made after `vm.$nextTick()` has resolved:
115
119
116
120
```js
117
121
// Inspect the generated HTML after a state update
118
-
it('updates the rendered message when vm.message updates', done=> {
119
-
constvm=newVue(MyComponent).$mount()
120
-
vm.message='foo'
121
-
122
-
// wait a "tick" after state change before asserting DOM updates
123
-
Vue.nextTick(() => {
124
-
expect(vm.$el.textContent).toBe('foo')
125
-
done()
126
-
})
122
+
it('updates the rendered message when wrapper.message updates', async () => {
123
+
constwrapper=shallowMount(MyComponent)
124
+
wrapper.setData({ message:'foo' })
125
+
126
+
// Wait a "tick" after state change before asserting DOM updates
0 commit comments