-
Notifications
You must be signed in to change notification settings - Fork 265
Bug: Reactivity issues with @vue/compat #1665
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
Comments
Curious, what if you try using import { flushPromises } from '@vue/test-utils'
const wrapper = mount(TestAsync, {
propsData: { done: renderedAsyncResolve }
});
await renderedAsync;
await flushPromises()
wrapper.vm.$nextTick(() => {
expect(wrapper.html()).toMatch('async');
done();
}); Is this just a race condition? |
Hey @lmiller1990 :) I added a test with flush promises and got the same results (works with vue 3, doesnt work with compat alias): it('with flushPromises', () => new Promise(async (done) => {
let renderedAsyncResolve;
const renderedAsync = new Promise(resolve => renderedAsyncResolve = resolve);
const wrapper = mount(TestAsync, {
propsData: { done: renderedAsyncResolve }
});
await renderedAsync;
await flushPromises();
wrapper.vm.$nextTick(() => {
expect(wrapper.html()).toMatch('async');
done();
});
})); Weetbix/vue-compat-composition-api-bug-repo@f0282f9 I think checking for the race condition was my original intention behind the |
@lmiller1990 any news on this? It seems that this issue makes Is it possibly the same issue as this? vuejs/vue-test-utils#1982 (comment) I'm not sure, because to use compat we have to set the vue alias, so I don't think there could be two imports resolving to different distributions.. Let me know if there is anything I can do to help! 🙏 |
I tried to reproduce in this code base so we could start working on a fix, but they all seem to pass, even in compat mode: https://github.com/vuejs/test-utils/compare/issue-1665?expand=1. I'll debug a bit more. I'm trying to reproduce with Jest to see if this is Vitest specific. |
Interesting. I did So... doesn't this mean the alias is not working as expected? I cannot help but think this is outside of Test Utils. We cannot change the import dynamically here - this would be up to the bundler or runner or whatever is executing the code. I'd be curious if Jest has the same problem. I tried running your reproduction with Jest but couldn't get it working (
Run with package.json{
"dependencies": {
"@vue/compat": "^3.2.37",
"@vue/test-utils": "^2.0.2",
"global-jsdom": "8.5.0",
"jsdom": "20.0.0",
"vue": "^3.2.37"
}
}
|
Edit: got it work with Jest as well, I configured cc @Weetbix - this seems like a Vite bug? |
I'll close this, as the upstream issue in Vitest mentions the proper solution (this was not an issue in VTU) |
Describe the bug
Reactivity does not seem to work when using the vue compat build.
For example all these tests will work with vue 3, but all will fail with @vue/compat:
To Reproduce
Check out this repo on the
jh/vue-utils-version
branch: https://github.com/Weetbix/vue-compat-composition-api-bug-repo/blob/jh/vue-utils-version/test.spec.jsRun
yarn test:vue3
to run in vue 3 and notice all tests pass.Run
yarn test:vue-compat
to run with the vue compat alias, notice all tests fail.Expected behavior
All tests should pass when running in compat mode. The templates/output should update to reflect the new values.
Related information:
@vue/test-utils
version:2.0.2
Vue
version:3.2.37
node
version:16.13.2
npm
(oryarn
) version: yarn1.22.19
Additional context
Originally raised in vue testing library: testing-library/vue-testing-library#275
Similar issues in vue 2.7 but seems to be caused by
vue-jest
: vuejs/vue-test-utils#1983The text was updated successfully, but these errors were encountered: