storybook/docs/snippets/react/single-story-test.ts.mdx
2023-08-01 14:47:37 +01:00

25 lines
557 B
Plaintext

```ts
// Form.test.ts|tsx
import { fireEvent, render, screen } from '@testing-library/react';
import { composeStory } from '@storybook/react';
import Meta, { ValidForm as ValidFormStory } from './LoginForm.stories';
const FormOK = composeStory(ValidFormStory, Meta);
test('Validates form', () => {
render(<FormOK />);
const buttonElement = screen.getByRole('button', {
name: 'Submit',
});
fireEvent.click(buttonElement);
const isFormValid = screen.getByLabelText('invalid-form');
expect(isFormValid).not.toBeInTheDocument();
});
```