mirror of
https://github.com/storybookjs/storybook.git
synced 2025-04-08 07:01:53 +08:00
38 lines
845 B
Plaintext
38 lines
845 B
Plaintext
```js
|
|
// tests/Form.test.js
|
|
|
|
import { fireEvent, render, screen } from '@testing-library/vue';
|
|
|
|
import { composeStories } from '@storybook/vue3';
|
|
|
|
import * as FormStories from './LoginForm.stories';
|
|
|
|
const { InvalidForm, ValidForm } = composeStories(FormStories);
|
|
|
|
test('Tests invalid form state', () => {
|
|
render(InvalidForm());
|
|
|
|
const buttonElement = screen.getByRole('button', {
|
|
name: 'Submit',
|
|
});
|
|
|
|
fireEvent.click(buttonElement);
|
|
|
|
const isFormValid = screen.getByLabelText('invalid-form');
|
|
expect(isFormValid).toBeInTheDocument();
|
|
});
|
|
|
|
test('Tests filled form', () => {
|
|
render(ValidForm());
|
|
|
|
const buttonElement = screen.getByRole('button', {
|
|
name: 'Submit',
|
|
});
|
|
|
|
fireEvent.click(buttonElement);
|
|
|
|
const isFormValid = screen.getByLabelText('invalid-form');
|
|
expect(isFormValid).not.toBeInTheDocument();
|
|
});
|
|
```
|