Skip to content

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

Closed
@matthew-white

Description

@matthew-white

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions