mirror of
https://github.com/storybookjs/storybook.git
synced 2025-04-08 11:11:53 +08:00
Add TS version of testing-library snippet
This commit is contained in:
parent
ffddc4b822
commit
9b95eaa3f7
@ -0,0 +1,19 @@
|
||||
```ts
|
||||
// Form.test.ts|tsx
|
||||
|
||||
import { render, fireEvent } from '@testing-library/react';
|
||||
|
||||
import { composeStory } from '@storybook/react';
|
||||
|
||||
import Meta, { InvalidForm } from './LoginForm.stories'; //👈 Our stories imported here.
|
||||
|
||||
it('Checks if the form is valid', () => {
|
||||
const ComposedInvalidForm = composeStory(InvalidForm, Meta);
|
||||
const { getByTestId, getByText } = render(<ComposedInvalidForm />);
|
||||
|
||||
fireEvent.click(getByText('Submit'));
|
||||
|
||||
const isFormValid = getByTestId('invalid-form');
|
||||
expect(isFormValid).toBeInTheDocument();
|
||||
});
|
||||
```
|
@ -78,6 +78,7 @@ For example, if you were working on a login component and wanted to test the inv
|
||||
<CodeSnippets
|
||||
paths={[
|
||||
'react/component-test-with-testing-library.js.mdx',
|
||||
'react/component-test-with-testing-library.ts.mdx',
|
||||
'vue/component-test-with-testing-library.js.mdx',
|
||||
'angular/component-test-with-testing-library.ts.mdx',
|
||||
'svelte/component-test-with-testing-library.js.mdx',
|
||||
|
Loading…
x
Reference in New Issue
Block a user