Skip to content

fix(#2541): stub globally registered components by their registration key - #2996

Open
ValentinYoushkevich wants to merge 1 commit into
vuejs:mainfrom
ValentinYoushkevich:fix/2541-stub-global-registration-key
Open

ValentinYoushkevich wants to merge 1 commit into
vuejs:mainfrom
ValentinYoushkevich:fix/2541-stub-global-registration-key

Conversation

@ValentinYoushkevich

Copy link
Copy Markdown
Contributor

A component registered with app.component() under a key that differs from its name (naive-ui registers Button as NButton, Arco as AButton) can't be stubbed by that key:

mount(Comp, { global: { plugins: [naive], stubs: { NButton: true } } })
// <n-button> still renders the real naive-ui button, only `stubs: { Button: true }` works

The stubs transformer only matched the key of locally registered components (instance.type.components) and the component name. It now also matches the key from the app registry (appContext.components), between those two, like Vue resolves components. A map from component to stub key is built once per app, so this doesn't add a lookup per stub on every render. Stubs that shallowMount creates for components not listed in stubs keep their name (button-stub); a listed key now names the stub (n-button-stub), as for local registrations. The same fix makes false work under shallow for a registration key that doesn't match the name: before, the name lookup ran next and overwrote it.

Real code that works around it by stubbing the internal name: wnzzer/rank-analysis Automation.tierSelect.spec.ts#L26-L32. With NSelect as the key, that spec fails on 2.5.1 and main and passes with this change.

Playground (2.5.1)

Fixes #2541

…ation key

A component registered with app.component() under a key that differs from its name could only be stubbed by its name. Also match the key from the app registry, between the local registration key and the name, using a map built once per app.
@netlify

netlify Bot commented Oct 30, 2026 •

Copy link
Copy Markdown

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

Name Link
🔨 Latest commit 63fcdec
🔍 Latest deploy log https://app.netlify.com/projects/vue-test-utils-docs/deploys/6ae4583a23aa9d57d402103e
😎 Deploy Preview https://deploy-preview-2996--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.

@pkg-pr-new

pkg-pr-new Bot commented Oct 30, 2026

Copy link
Copy Markdown

Open in StackBlitz

npm i https://pkg.pr.new/@vue/test-utils@2996

commit: 63fcdec

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.

Bug: stubs does not respect globally registered component names

1 participant