Environment
- Operating system macOS 25.1.0
- CPU Apple M1 Pro (10 cores)
- Node.js version v22.13.1
- nuxt/cli version 3.32.0
- Package manager yarn 4.6.0
- Nuxt version 3.13.2
- Nitro version 2.13.1
- Builder vite 7.3.0
- Config -
- Modules -
Reproduction
NA
Describe the bug
sb.mock() in .storybook/preview.ts doesn't work with @storybook-vue/nuxt. The mocked() helper returns the original function instead of a mock function.
Steps to Reproduce
- Set up module mocking in
.storybook/preview.ts:
import { sb } from "storybook/test";
sb.mock(import("../composables/useMyComposable.ts"), { spy: true });
- Use mocked() in a story:
import { mocked, fn } from "storybook/test";
import { useMyComposable } from "../composables/useMyComposable.ts";
export const Default: Story = {
beforeEach: async () => {
mocked(useMyComposable).mockReturnValue({
// mock return value
});
},
};
- Run Storybook and navigate to the story
Expected Behavior
mocked(useMyComposable) should return a mock function with mockReturnValue, mockImplementation, etc.
Actual Behavior
TypeError: mocked(...).mockReturnValue is not a function
The mocked() function returns the original function unchanged, without mock capabilities.
Workaround
It worked by adding the following code to .storybook/main.ts
import { createRequire } from "node:module";
import { dirname, join } from "node:path";
const config: StorybookConfig = {
// ... other config
async viteFinal(config, options) {
// Call @storybook/builder-vite's viteFinal to enable viteMockPlugin
const require = createRequire(import.meta.url);
const vue3VitePath = dirname(require.resolve("@storybook/vue3-vite/package.json"));
const builderVitePresetPath = join(vue3VitePath, "node_modules/@storybook/builder-vite/dist/preset.js");
const { viteFinal: builderViteFinal } = await import(builderVitePresetPath);
return builderViteFinal(config, options);
},
};
Additional context
Environment
Reproduction
NA
Describe the bug
sb.mock()in.storybook/preview.tsdoesn't work with@storybook-vue/nuxt. Themocked()helper returns the original function instead of a mock function.Steps to Reproduce
.storybook/preview.ts:Expected Behavior
mocked(useMyComposable) should return a mock function with mockReturnValue, mockImplementation, etc.
Actual Behavior
The mocked() function returns the original function unchanged, without mock capabilities.
Workaround
It worked by adding the following code to .storybook/main.ts
Additional context