mirror of
https://github.com/storybookjs/storybook.git
synced 2025-04-07 23:02:00 +08:00
20 lines
612 B
Plaintext
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();
|
|
});
|
|
```
|