storybook/docs/snippets/react/component-test-with-testing-library.ts.mdx
2023-06-02 16:50:46 +01:00

25 lines
612 B
Plaintext

```ts
// Form.test.ts|tsx
import { fireEvent, render, screen } from '@testing-library/react';
import { composeStory } from '@storybook/react';
import Meta, { InvalidForm as InvalidFormStory } from './LoginForm.stories'; //👈 Our stories imported here.
const FormError = composeStory(InvalidFormStory, Meta);
test('Checks if the form is valid', () => {
render(<FormError />);
const buttonElement = screen.getByRole('button', {
name: 'Submit',
});
fireEvent.click(buttonElement);
const isFormValid = screen.getByLabelText('invalid-form');
expect(isFormValid).toBeInTheDocument();
});
```