-
Notifications
You must be signed in to change notification settings - Fork 1.4k
docs: Testing docs #9164
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
docs: Testing docs #9164
Changes from all commits
edeaa2f
8a1f97e
28eb788
457c59a
a15c24f
819c076
3b991ea
42b0406
36f1a6f
e2b29c9
4c94cd0
83262ef
5d2b172
980d3d6
59e9400
a414886
0b2751d
4ef4996
b04b7af
807beb0
68a66e0
432f702
78fb92b
620ebd7
6fdf671
c051a8c
159e76b
50c9e07
5a10ff0
5b9fda5
6db86ef
0c6ac3f
a3d57a9
30bab22
44b0d8d
5084b6b
34ad8cc
6bf1724
6e508f2
73626ea
e799a04
f8ec2fb
4b38f98
2e13868
6f69d9e
cad6874
10d231d
2189b24
e2a12f3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,66 @@ | ||||||||||||||||||||
| import {Layout} from '../../../src/Layout'; | ||||||||||||||||||||
| export default Layout; | ||||||||||||||||||||
|
|
||||||||||||||||||||
| import {InlineAlert, Heading, Content} from '@react-spectrum/s2'; | ||||||||||||||||||||
| import testUtilDocs from 'docs:@react-aria/test-utils'; | ||||||||||||||||||||
| import {InstallCommand} from '../../../src/InstallCommand'; | ||||||||||||||||||||
| import {PatternTestingFAQ} from '../../../src/PatternTestingFAQ'; | ||||||||||||||||||||
|
|
||||||||||||||||||||
| export const isSubpage = true; | ||||||||||||||||||||
| export const tags = ['testing', 'checkboxgroup', 'test-utils']; | ||||||||||||||||||||
| export const description = 'Testing CheckboxGroup with React Aria test utils'; | ||||||||||||||||||||
|
|
||||||||||||||||||||
| # Testing CheckboxGroup | ||||||||||||||||||||
|
|
||||||||||||||||||||
| ## Test utils | ||||||||||||||||||||
|
|
||||||||||||||||||||
| `@react-aria/test-utils` offers common checkbox group interaction utilities which you may find helpful when writing tests. To install, simply | ||||||||||||||||||||
| add it to your dev dependencies via your preferred package manager. | ||||||||||||||||||||
|
Comment on lines
+17
to
+18
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||||
|
|
||||||||||||||||||||
| <InstallCommand pkg="@react-aria/test-utils" flags="--dev" /> | ||||||||||||||||||||
|
|
||||||||||||||||||||
| <InlineAlert variant="notice"> | ||||||||||||||||||||
| <Heading>Requirements</Heading> | ||||||||||||||||||||
| <Content>Please note that this library uses [@testing-library/react@16](https://www.npmjs.com/package/@testing-library/react) and [@testing-library/user-event@14](https://www.npmjs.com/package/@testing-library/user-event). This means that you need to be on React 18+ in order for these utilities to work.</Content> | ||||||||||||||||||||
| </InlineAlert> | ||||||||||||||||||||
|
|
||||||||||||||||||||
| Once installed, you can access the `User` that `@react-aria/test-utils` provides in your test file as shown below. This user only needs to be initialized once and then can be used to generate | ||||||||||||||||||||
| the `CheckboxGroup` tester in your test cases. This gives you access to `CheckboxGroup` specific utilities that you can then call within your test to query for specific subcomponents or simulate common interactions. | ||||||||||||||||||||
| The example test case below shows how you might go about setting up the `CheckboxGroup` tester, use it to simulate checkbox selection, and verify the checkbox group's state after each interaction. | ||||||||||||||||||||
|
Comment on lines
+27
to
+29
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||||
|
|
||||||||||||||||||||
| ```ts | ||||||||||||||||||||
| // CheckboxGroup.test.ts | ||||||||||||||||||||
| import {render} from '@testing-library/react'; | ||||||||||||||||||||
| import {User} from '@react-aria/test-utils'; | ||||||||||||||||||||
|
|
||||||||||||||||||||
| let testUtilUser = new User({interactionType: 'mouse', advanceTimer: jest.advanceTimersByTime}); | ||||||||||||||||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||||
| // ... | ||||||||||||||||||||
|
|
||||||||||||||||||||
| it('CheckboxGroup can select multiple checkboxes', async function () { | ||||||||||||||||||||
| // Render your test component/app and initialize the checkbox group tester | ||||||||||||||||||||
| let {getByTestId} = render( | ||||||||||||||||||||
| <CheckboxGroup data-testid="test-checkboxgroup"> | ||||||||||||||||||||
| ... | ||||||||||||||||||||
| </CheckboxGroup> | ||||||||||||||||||||
| ); | ||||||||||||||||||||
| let checkboxGroupTester = testUtilUser.createTester('CheckboxGroup', {root: getByTestId('test-checkboxgroup')}); | ||||||||||||||||||||
| expect(checkboxGroupTester.selectedCheckboxes).toHaveLength(0); | ||||||||||||||||||||
|
|
||||||||||||||||||||
| await checkboxGroupTester.toggleCheckbox({checkbox: 0}); | ||||||||||||||||||||
| expect(checkboxGroupTester.checkboxes[0]).toBeChecked(); | ||||||||||||||||||||
| expect(checkboxGroupTester.selectedCheckboxes).toHaveLength(1); | ||||||||||||||||||||
|
|
||||||||||||||||||||
| await checkboxGroupTester.toggleCheckbox({checkbox: 4}); | ||||||||||||||||||||
| expect(checkboxGroupTester.checkboxes[4]).toBeChecked(); | ||||||||||||||||||||
| expect(checkboxGroupTester.selectedCheckboxes).toHaveLength(2); | ||||||||||||||||||||
| }); | ||||||||||||||||||||
| ``` | ||||||||||||||||||||
|
|
||||||||||||||||||||
| See below for the full definition of the `User` and the `CheckboxGroup` tester. | ||||||||||||||||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||||
|
|
||||||||||||||||||||
| <ClassAPI links={testUtilDocs.links} class={testUtilDocs.exports.User} /> | ||||||||||||||||||||
| <ClassAPI links={testUtilDocs.links} class={testUtilDocs.exports.CheckboxGroupTester} /> | ||||||||||||||||||||
|
Comment on lines
+61
to
+62
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
also do we need to repeat the |
||||||||||||||||||||
|
|
||||||||||||||||||||
| ## Testing FAQ | ||||||||||||||||||||
|
|
||||||||||||||||||||
| <PatternTestingFAQ patternName="checkbox group" /> | ||||||||||||||||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we want this repeated on each page or added to the testing guide? |
||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this won't have been released yet either, does that matter?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah this I'm not going to put into the docs deploy. But in the final release these new testers will be made available so I'll merge that in then