Skip to content

fix: apply global mocks named after internal instance fields - #2977

Open
ValentinYoushkevich wants to merge 1 commit into
vuejs:mainfrom
ValentinYoushkevich:fix/mocks-reserved-names
Open

ValentinYoushkevich wants to merge 1 commit into
vuejs:mainfrom
ValentinYoushkevich:fix/mocks-reserved-names

Conversation

@ValentinYoushkevich

Copy link
Copy Markdown
Contributor

global.mocks with a name like $u (uView), $m, $c or $a is never applied: the mocks mixin does this[k] = v, and Vue's instance proxy refuses to set $x when x is an internal instance field (u holds the updated hooks). The mixin throws, so mount, shallowMount and renderToString all fail, also for <script setup> components (the mixin runs on the VTU root as well).

const Comp = defineComponent({ template: '<div>{{ $u.title }}</div>' })
mount(Comp, { global: { mocks: { $u: { title: 'mocked' } } } })
// [Vue warn]: Attempting to mutate public property "$u"...
// TypeError: 'set' on proxy: trap returned falsish for property '$u'

The mixin now defines these mocks directly on the instance context, which the proxy reads them from. Object.defineProperty is used so that the mock also overrides a real $u installed by the plugin in globalProperties (this is what Vue itself does for global properties). Other mocks still go through the proxy as before.

uview-plus installs $u as a global property and uses it from components, e.g. index.js and login/index.vue.

Repro on 2.5.1: playground

The public instance proxy refuses to set `$x` when `x` is an internal
field of the component instance, so mocks like `$u` (uView) made the
mocks mixin throw. Define these mocks directly on the instance context.
@netlify

netlify Bot commented Oct 21, 2026

Copy link
Copy Markdown

✅ Deploy Preview for vue-test-utils-docs ready!

Name Link
🔨 Latest commit 3fcef5f
🔍 Latest deploy log https://app.netlify.com/projects/vue-test-utils-docs/deploys/6ad8dca584b7c93a82fa7b6d
😎 Deploy Preview https://deploy-preview-2977--vue-test-utils-docs.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

This branch has not been deployed

No deployments
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

Successfully merging this pull request may close these issues.

1 participant