Skip to content
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

template fails to re-render when ref value is changed under test when using vue@2.7.3 #1982

Open
admhpr opened this issue Jul 6, 2022 · 7 comments
Labels

Comments

@admhpr
Copy link

admhpr commented Jul 6, 2022

Subject of the issue

template fails to re-render when ref value is changed under test when using vue@2.7.3

template does update with user interaction in browser.

elements using v-if directive fail to re-render when predicate value changes during unit testing.

Steps to reproduce

https://codesandbox.io/s/fervent-tdd-fijnxf

run npm run test

Expected behaviour

template is re-rendered and relevant elements found using wrapper.find/wrapper.findAll

Actual behaviour

no change in template

Possible Solution

?

much appreciated!

@kingyue737
Copy link

elements using v-for directive do not update either

@admhpr
Copy link
Author

admhpr commented Jul 11, 2022

likely related #1983

@kingyue737
Copy link

likely related #1983

I don't think so. Their issue is related to vue-jest, while we use vitest.

@lmiller1990
Copy link
Member

Could be a bit of both. Likely both Vue Jest and Test Utils need patching.

@dneuschaefer-rube
Copy link

I believe this is a case of the dual package hazard that has already caused issues at other places (see e.g. vuejs/vue#12626).

Essentially, the vite plugin for vue2 aliases vue imports to the ESM file (vue.runtime.esm.js), while imports through VTU go to vue.runtime.mjs, which re-exports from vue.runtime.common.js. That means that watchers imported from other files (e.g. through composables) or the watcher to re-render the template are set up on a the wrong Vue instance, and thus don't trigger as expected.

Unfortunately I'm not sure what the "proper" workaround for that is; I could see the root issue being with the vite plugin, the way VTU imports Vue, or even with the exports declaration from the vue package. Maybe someone else has a better understanding there.

What does work as a temporary fix though is to override the resolve alias defined through the vite plugin in your test config:

resolve: {
    alias: {
        vue: 'vue/dist/vue.runtime.mjs',
    },
},

While there's good reason to use the ESM build in production, that should be fine for the test execution.

@kingyue737
Copy link

@dneuschaefer-rube All tests pass. Thanks!!

@lmiller1990
Copy link
Member

I looked into this here vuejs/test-utils#1665 (comment)

I think there might be a bug in Vitest around resolving the correct module for Vue compat. I don't know if it's related to the issue here, but this info might help people from from Google with a Vitest/Test Utils/compat issue.

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

No branches or pull requests

5 participants