-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
[UI v2] Setup Storybook #16003
[UI v2] Setup Storybook #16003
Conversation
65bac82
to
c93f420
Compare
export const TestAddRemove: Story = { | ||
name: "Test: Add and remove", | ||
play: async ({ canvasElement, step }) => { | ||
const canvas = within(canvasElement); | ||
const tagsInput: HTMLInputElement = canvas.getByRole("textbox"); | ||
|
||
await step("Add testTag", async () => { | ||
await userEvent.type(tagsInput, "testTag"); | ||
await expect(tagsInput.value).toBe("testTag"); | ||
await userEvent.type(tagsInput, "{enter}"); | ||
await expect(tagsInput.value).toBe(""); | ||
await expect(canvas.queryByText("testTag")).not.toBeNull(); | ||
}); | ||
|
||
await step("Add testTag2", async () => { | ||
await userEvent.type(tagsInput, "testTag2{enter}"); | ||
}); | ||
|
||
await step("Delete testTag", async () => { | ||
await userEvent.click(canvas.getAllByRole("button")[0]); | ||
await expect(canvas.queryByText("testTag")).toBeNull(); | ||
}); | ||
}, | ||
}; |
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 is neat! I haven't seen tests written with Storybook before. Does this have any advantages over our current vitest
+ testing-library
setup?
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.
I didn't set up the test runner for it on CI (I can add it to this PR or another PR if you're interested), so it is more for development than testing.
- The play function further reduces the feedback loop on local-dev
- The time travel feature helps with debugging
Please see the live version here.
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.
As the Storybook test also uses vitest + testing-library
, here’s one potential workflow without a test runner for the Storybook tests:
- Use the Storybook play function to facilitate local development.
- Once development is completed, copy the Storybook test into the test suite.
- Clean up the Storybook stories and tests, keep only the stories/tests for documentation purposes.
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.
Thanks for contributing!
closes #15998
Checklist
<link to issue>
"mint.json
.