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
I have a test for a watcher that aims to test the outcome of a data property changing from one non-initial value to another non-initial value, e.g.
{
data () {
return {
gid: null
}
},
watch: {
gid (newVal, oldVal) {
if (oldVal) { /* Do B */ }
if (newVal) { /* Do A */ }
}
}
}
The test wants to see the outcome of /* Do B */. Obviously, this can be done by mounting the component, changing the value, waiting for next tick, changing the value again, waiting for next tick again, and then making the assertion. Another way that I've done this is by using the before option, e.g.
describe('gid watcher', () => {
it('should Do A and Do B when gid changes from an existing value to a new existing value', async () => {
let before = (component) => {
let data = component.data()
component.data = () => ({ ...data, gid: 123 })
}
let vm = shallow(Component, { before })
vm.gid = 321
await vm.$nextTick()
expect(/* to have done A and B */)
})
})
All of this works fine, but it seems like there should be an easier way to set initial data values to test individual watchers and methods.
The text was updated successfully, but these errors were encountered:
I have a test for a watcher that aims to test the outcome of a data property changing from one non-initial value to another non-initial value, e.g.
The test wants to see the outcome of
/* Do B */
. Obviously, this can be done by mounting the component, changing the value, waiting for next tick, changing the value again, waiting for next tick again, and then making the assertion. Another way that I've done this is by using thebefore
option, e.g.All of this works fine, but it seems like there should be an easier way to set initial data values to test individual watchers and methods.
The text was updated successfully, but these errors were encountered: