Skip to content

Commit f8447c8

Browse files
Merge pull request #779 from chromaui/ui_testing_update_component_testing
Docs: UI testing handbook minor fixes
2 parents ddc7080 + 826048f commit f8447c8

File tree

5 files changed

+14
-14
lines changed

5 files changed

+14
-14
lines changed

content/ui-testing-handbook/react/en/accessibility-testing.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ To install the addon, run: `yarn add --dev @storybook/addon-a11y`. Then, add `'@
5858
```diff:title=.storybook/main.js
5959
/** @type { import('@storybook/react-vite').StorybookConfig } */
6060
const config = {
61-
stories: ['../src/**/*.mdx', '../src/**/*.stories.@(js|jsx|ts|tsx)'],
61+
stories: ['../src/**/*.stories.@(js|jsx|ts|tsx)'],
6262
staticDirs: ['../public'],
6363
addons: [
6464
'@storybook/addon-links',

content/ui-testing-handbook/react/en/composition-testing.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ yarn init-msw
187187

188188
<div class="aside">
189189

190-
💡 Public directory may differ depending on the project. For custom configurations, we recommend reading MSW's [documentation](https://mswjs.io/docs/getting-started/integrate/browser#where-is-my-public-directory) to learn more about them. To see the changes reflected in Storybook, you'll need to update the [`staticDirs`](https://storybook.js.org/docs/configure/images-and-assets#serving-static-files-via-storybook-configuration) configuration element in `.storybook/main.js`.
190+
💡 Public directory may differ depending on the project. For custom configurations, we recommend reading MSW's [documentation](https://mswjs.io/docs/getting-started/integrate/browser#where-is-my-public-directory) to learn more about them. To see the changes reflected in Storybook, you'll need to update the [`staticDirs`](https://storybook.js.org/docs/configure/integration/images-and-assets#serving-static-files-via-storybook-configuration) configuration element in `.storybook/main.js`.
191191

192192
</div>
193193

content/ui-testing-handbook/react/en/interaction-testing.md

+9-9
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,9 @@ Lastly, start up your Storybook (the test runner will run against your local Sto
5757
yarn storybook
5858
```
5959

60-
## Reuse stories as interaction test cases
60+
## Reuse stories as component test cases
6161

62-
In the previous chapter, we catalogued all the use cases of the InboxScreen component in the `InboxScreen.stories.jsx` file. That allowed us to spot-check appearance during development and catch regressions via visual tests. These stories will now also power our interaction tests.
62+
In the previous chapter, we catalogued all the use cases of the InboxScreen component in the `InboxScreen.stories.jsx` file. That allowed us to spot-check appearance during development and catch regressions via visual tests. These stories will now also power our component tests.
6363

6464
```javascript:title=src/InboxScreen.stories.jsx
6565
import { http, HttpResponse } from 'msw';
@@ -101,13 +101,13 @@ export const Error = {
101101
};
102102
```
103103

104-
### Write an interaction test using the play function
104+
### Write a component test using the play function
105105

106-
[Testing Library](https://testing-library.com/) offers a convenient API for simulating user interactions—click, drag, tap, type, etc. Whereas [Jest](https://jestjs.io/) provides assertion utilities. We'll use Storybook-instrumented versions of these two tools to write the test. Therefore, you get a familiar developer-friendly syntax to interact with the DOM, but with extra telemetry to help with debugging.
106+
[Testing Library](https://testing-library.com/) offers a convenient API for simulating user interactions—click, drag, tap, type, etc. Whereas [Vitest](https://vitest.dev/) provides assertion utilities. We'll use Storybook-instrumented versions of these two tools to write the test. Therefore, you get a familiar developer-friendly syntax to interact with the DOM, but with extra telemetry to help with debugging.
107107

108108
The test itself will be housed inside a [play function](https://storybook.js.org/docs/writing-stories/play-function). This snippet of code gets attached to a story and runs after the story is rendered.
109109

110-
Let's add in our first interaction test to verify that the user can pin a task:
110+
Let's add in our first component test to verify that the user can pin a task:
111111

112112
```javascript:title=src/InboxScreen.stories.jsx
113113
import { http, HttpResponse } from 'msw';
@@ -152,7 +152,7 @@ Each play function receives the Canvas element—the top-level container of the
152152

153153
We're looking for the "Export logo" task in our case. Then find the pin button within it and click it. Finally, we check to see if the button has updated to the unpinned state.
154154

155-
When Storybook finishes rendering the story, it executes the steps defined within the play function, interacting with the component and pinning a task—similar to how a user would do it. If you check your [interactions panel](https://storybook.js.org/docs/writing-tests/interaction-testing#interactive-debugger), you'll see the step-by-step flow. It also offers a handy set of UI controls to pause, resume, rewind, and step through each interaction.
155+
When Storybook finishes rendering the story, it executes the steps defined within the play function, interacting with the component and pinning a task—similar to how a user would do it. If you check your [interactions panel](https://storybook.js.org/docs/writing-tests/component-testing#interactive-debugger), you'll see the step-by-step flow. It also offers a handy set of UI controls to pause, resume, rewind, and step through each interaction.
156156

157157
<video autoPlay muted playsInline loop>
158158
<source
@@ -202,9 +202,9 @@ export const EditTask = {
202202
};
203203
```
204204

205-
You should now see stories for these scenarios. Storybook only runs the interaction test when you’re viewing a story. Therefore, you'd have to go through each story to run all your checks.
205+
You should now see stories for these scenarios. Storybook only runs the component test when you’re viewing a story. Therefore, you'd have to review each story to run all your checks.
206206

207-
It's unrealistic to manually review the entire Storybook whenever you make a change. Storybook test runner automates that process. It's a standalone utility—powered by [Playwright](https://playwright.dev/)—that runs all your interactions tests and catches broken stories.
207+
It's unrealistic to manually review the entire Storybook whenever you make a change. Storybook test runner automates that process. It's a standalone utility—powered by [Playwright](https://playwright.dev/)—that runs all your tests and catches broken stories.
208208

209209
![](/ui-testing-handbook/inbox-screen-interaction-test.png)
210210

@@ -220,7 +220,7 @@ It'll verify whether all stories rendered without any errors and that all assert
220220

221221
![](/ui-testing-handbook/storybook-test-runner-story-error.png)
222222

223-
In summary, the setup code and test both collocated in the stories file. Using a play function, we interacted with the UI the way a user would. Storybook interaction tests combine the intuitive debugging environment of a live browser with the performance and scriptability of headless browsers.
223+
In summary, the setup code and test are both located in the stories file. Using a play function, we interacted with the UI as a user would. Storybook component tests combine the intuitive debugging environment of a live browser with the performance and scriptability of headless browsers.
224224

225225
## Catching usability issues
226226

content/ui-testing-handbook/react/en/introduction.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ The teams I interviewed all had similar tactics despite differences in their siz
5656

5757
- 📚 **Isolate components using** [Storybook](http://storybook.js.org/). Write test cases where each state is reproduced using props and mock data.
5858
-**Catch visual bugs and verify composition** using [Chromatic](https://www.chromatic.com/?utm_source=storybook_website&utm_medium=link&utm_campaign=storybook).
59-
- 🐙 **Verify interactions** with [Jest](https://jestjs.io/) and [Testing Library](https://testing-library.com/).
59+
- 🐙 **Verify interactions** with [Vitest](https://vitest.dev/) and [Testing Library](https://testing-library.com/).
6060
- ♿️ **Audit accessibility** of your components using [Axe](https://www.deque.com/axe/).
6161
- 🔄 **Verify user flows** by writing end-to-end tests with [Cypress](https://www.cypress.io/).
6262
- 🚥 **Catch regressions** by automatically running tests with [GitHub Actions](https://github.com/features/actions).

content/ui-testing-handbook/react/en/workflow.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ To catch regressions you need to run on all your components. You can do that by
8484

8585
![](/ui-testing-handbook/ci-a11y.png)
8686

87-
### Interaction tests
87+
### Component tests
8888

8989
The user can delete a task by clicking on the _trash can_ button, we’ll need to add in a test to verify that behaviour.
9090

@@ -97,7 +97,7 @@ The user can delete a task by clicking on the _trash can_ button, we’ll need t
9797

9898
#### During development
9999

100-
During development, manually verify the interaction using the InboxScreen stories. If it’s working as expected, you can add in an interaction test using a play function.
100+
During development, manually verify the interaction using the InboxScreen stories. If it works as expected, you can add a component test using a play function.
101101

102102
```javascript:title=src/InboxScreen.stories.jsx
103103
// ... code omitted for brevity ...

0 commit comments

Comments
 (0)