storybook/docs/snippets/vue/portable-stories-vitest-compose-story.ts.mdx
Kyle Gach e09480aefb Split into three separate pages
- Organizational and prose improvements
- Remove Cypress, for now
2024-02-27 11:09:42 -07:00

20 lines
612 B
Plaintext

```ts
// Button.test.ts
import { vi, test, expect } from 'vitest';
import { render, screen } from '@testing-library/vue';
import { composeStory } from '@storybook/vue3';
import meta, { Primary } from './Button.stories';
test('onclick handler is called', () => {
// Returns a story which already contains all annotations from story, meta and global levels
const PrimaryStory = composeStory(Primary, meta);
const onClickSpy = vi.fn();
render(Primary({ onClick: onClickSpy }));
const buttonElement = screen.getByRole('button');
buttonElement.click();
expect(onClickSpy).toHaveBeenCalled();
});
```