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

25 lines
557 B
Plaintext

```js
// Form.test.js|jsx
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();
});
```