Skip to content

feat: add mockComponent - #1149

Open
huang-julien wants to merge 1 commit into
mainfrom
feat/mock-component
Open

huang-julien wants to merge 1 commit into
mainfrom
feat/mock-component

Conversation

@huang-julien

Copy link
Copy Markdown
Collaborator

🔗 Linked issue

This PR introduce mockComponent, similar to the one from nuxt test utils.

  • top level call only
  • name is typed from #components without the lazy variants. A typo or a Lazy name is a type error
  • server components are mockable

HOw it works

When Storybook start,the addon scans the story files for mockComponent calls and matches the names against the components Nuxt registered
for each matched component file:

  • Vite is told to serve a thin wrapper instead of the file itself.
  • The wrapper re-exports everything from the original and replaces the component export with a proxy

Each story creates its own Nuxt app. While it boots, the addon runs the files factories and stores the results on that app.
The mock provider at render time looks up the current app and renders the mock if the file registered one, otherwise the original component.

📚 Description

@netlify

netlify Bot commented Oct 23, 2026 •

Copy link
Copy Markdown

❌ Deploy Preview for nuxt-storybook failed. Why did it fail? →

Name Link
🔨 Latest commit 09ff275
🔍 Latest deploy log https://app.netlify.com/projects/nuxt-storybook/deploys/6adbca60d3c729e2d591290f

@pkg-pr-new

pkg-pr-new Bot commented Oct 23, 2026

Copy link
Copy Markdown

Open in StackBlitz

npm i https://pkg.pr.new/@nuxtjs/storybook@1149
npm i https://pkg.pr.new/@storybook-vue/nuxt@1149

commit: 09ff275

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