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

Bug: vm does not provide access to global properties for Composition API component #2140

Closed
matthew-white opened this issue Jul 25, 2023 · 1 comment · Fixed by #2386
Closed
Labels
bug Something isn't working

Comments

@matthew-white
Copy link

matthew-white commented Jul 25, 2023

Describe the bug

I sometimes use the vm property of a Wrapper to access global properties. This comes up most often in tests that use a real router, then make an assertion about vm.$route. However, it seems that vm does not provide access to global properties for Composition API components.

To Reproduce

https://github.com/matthew-white/global-properties-repro/blob/master/src/components/__tests__/HelloWorld.spec.js

In this repository, there are 4 variations on a component. A plugin adds a global property named foo. For 2 of the components, vm.foo is defined, but for the other 2, vm.foo is not defined. This is what I see when I run tests:

✓ provides access to a global property from an Options API component
× provides access to a global property from a Composition API component
× provides access to a global property from an Options API component with a setup() function
✓ provides access to a global property from an Options API component with a setup() function that does not return

Expected behavior

It would be great to be able to access global properties from vm for all components.

Related information:

npmPackages:
@vue/test-utils: ^2.4.1 => 2.4.1
vitest: ^0.33.0 => 0.33.0
vue: ^3.3.4 => 3.3.4

Additional context

Just to link issues, I think this issue may be related to #2008.

@cexbrayat
Copy link
Member

Hi @matthew-white

Thanks for the detailled repro 👍 It indeed looks like an issue.

Would you like to try your hand at a PR to fix it? This would be a great help!

cexbrayat pushed a commit that referenced this issue Mar 27, 2024
createVMProxy function has been fixed to also return global properties.

Fixes #2140
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants