Skip to content

setData has no effect starting with version 1.0.0-beta-30 #1447

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
rowild opened this issue Feb 24, 2020 · 6 comments
Closed

setData has no effect starting with version 1.0.0-beta-30 #1447

rowild opened this issue Feb 24, 2020 · 6 comments

Comments

@rowild
Copy link

rowild commented Feb 24, 2020

Version

1.0.0-beta.31

Reproduction link

https://github.com/rowild/vue-unit-testing

Steps to reproduce

Please checkout the repo, which contains 2 simple tests, and run the tests like this:

  1. npm i -D @vue/[email protected]
  2. npm run test:unit

The second test, which uses setData(), fails. Same thing with beta.30.

Please continue with:

  1. npm i -D @vue/[email protected]
  2. npm run test:unit

Now both tests work fine.

What is expected?

Both tests in the example repo should work.

What is actually happening?

Starting with 1.0.0-beta.30 the test that uses "setData()" does not work anymore.


This is a test example that is explained in the Vuemastery "Unit testing" course (link in the readme of the repository), which is, why I assume it is the correct way of writing a test.

@dobromir-hristov
Copy link
Contributor

This fixes it for you, its because this requires the template to re-render, on next tick :)

test('If logged in, show Logout button.', async () => {
    const wrapper = mount(AppHeader)
    wrapper.setData({ loggedIn: true })
    await wrapper.vm.$nextTick()
    expect(wrapper.find('button').isVisible()).toBe(true)
  })

@rowild
Copy link
Author

rowild commented Feb 24, 2020

Thank you for your quick response! Is this going to be the standard behaviour in vue-test-utils? Did I miss some documentation? Could you please point me to the place, where I can read about that?

@dobromir-hristov
Copy link
Contributor

https://vue-test-utils.vuejs.org/guides/#using-nexttick

We will make this process easier in the next version of VTU.

@rowild
Copy link
Author

rowild commented Feb 24, 2020

Wow - you are really quick! Thank you so much!

@rowild
Copy link
Author

rowild commented Feb 24, 2020

Need to ask once more: It was not the case with beta.29 that async/await was necessary. What was the reason to change that behaviour?

@dobromir-hristov
Copy link
Contributor

#1137

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants