Skip to content

[Bug]: Canvas types only exist if storybook/test is imported #32972

@yannbf

Description

@yannbf

Describe the bug

As can be seen here:

Reproduction link

https://stackblitz.com/edit/github-8sdhkcnj?file=src%2Fstories%2FButton.stories.ts&preset=node

Reproduction steps

import type { Meta, StoryObj } from '@storybook/react-vite';

// By commenting this out, the type error in line 22 will stop.
// import { fn } from 'storybook/test';

import { Button } from './Button';

const meta = {
  title: 'Example/Button',
  component: Button,
} satisfies Meta<typeof Button>;

export default meta;
type Story = StoryObj<typeof meta>;

export const Default: Story = {
  args: {
    primary: true,
    label: 'Button',
  },
  play: async ({ canvas }) => {
    canvas.getByRole('button');
  },
};

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions