If execute a test by the first time, for instance:
test('simple test', () => {
const wrapper = shallowMount(App, {
Vue,
}
})
wrapper.setData({
test: "test",
})
expect(wrapper.element).toMatchSnapshot()
})
I expect that the snapshot generated has to include the data test: "test" rendered but the result is that I see the default values (defined in the App component) instead.
specify in the docs a guide that explains deeper the setData method.
Hi,
can you provide a reproduction link or a complete example?
That being said, have you tried looking for "test" (using find() or similar) instead of using a snapshot? That would remove a whole collection of potential issues.
You may need to do
test('simple test', async () => {
const wrapper = shallowMount(App, {
Vue,
}
})
await wrapper.setData({
test: "test",
})
expect(wrapper.element).toMatchSnapshot()
})
await can force the test to wait for Vue to update the DOM. I could be wrong - I don't have much exp. around snapshots. I like to use expect(wrapper.html()).toContain('test').
(assuming shallowMount is not stubbing out the component that should be rendering test).
Hi,
can you provide a reproduction link or a complete example?
That being said, have you tried looking for
"test"(usingfind()or similar) instead of using a snapshot? That would remove a whole collection of potential issues.
I'm using "toMatchSnapshot()" doing to the test example provided by the Apollo testing guide (https://apollo.vuejs.org/guide/testing.html#simple-tests)
I'll try with other methods, thanks
You may need to do
test('simple test', async () => { const wrapper = shallowMount(App, { Vue, } }) await wrapper.setData({ test: "test", }) expect(wrapper.element).toMatchSnapshot() })
awaitcan force the test to wait for Vue to update the DOM. I could be wrong - I don't have much exp. around snapshots. I like to useexpect(wrapper.html()).toContain('test').(assuming
shallowMountis not stubbing out the component that should be renderingtest).
Using async/await worked! Thanks.
Most helpful comment
I'm using "toMatchSnapshot()" doing to the test example provided by the Apollo testing guide (https://apollo.vuejs.org/guide/testing.html#simple-tests)
I'll try with other methods, thanks
Using async/await worked! Thanks.