-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
Editor: Refactor PostPublishButton
tests to @testing-library/react
#43909
Conversation
Size Change: +1.92 kB (0%) Total Size: 1.25 MB
ℹ️ View Unchanged
|
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.
Rewrite is looking good!
Couple of notes:
- I noticed that the
isToggle
property (and all of the relative branches that the component can take) don't seem to be tested - There's another test file (
label.js
) that is exclusively testing for all possible label values thatPublishButtonLabel
can have — it would be great if we could simply add those assertions to the main test suite by checking but the button's accessible name (i.e.getByRole('button', {name: 'Label to test for'})
), and therefore remote the separate test file.
Of course, feel free to merge this PR as-is if you'd rather focus exclusively on the RTL migration
It would be great if we could also add the expected button label for all the tests assertions — it would greatly increase the value of these tests. (eg. `getByRole('button', {name:
I see, but as you mentioned, I'm not aiming to enrich tests or get to a full test coverage here, but rather focus on the migration to RTL. This could be a good idea for someone to pick up separately though.
I think that's not necessary. These are nicely separated right now, and it only makes sense that their tests are also separated. The label ones don't even require rendering, so I think I prefer keeping them as they are.
Yeah, thanks for that - it's my personal preference as I'm focusing on getting rid of enzyme in particular.
I don't mind, although I'm not sure how valuable this will be, considering that existing tests don't seem to fully cover all cases with all the available props. Added in c25047d though. |
What?
We've recently started refactoring
enzyme
tests to@testing-library/react
.This PR refactors the
<PostPublishButton />
component tests fromenzyme
to@testing-library/react
.Why?
@testing-library/react
provides a better way to write tests for accessible components that is closer to the way the user experiences them.How?
We're straightforwardly replacing
enzyme
tests with@testing-library/react
ones, usingjest-dom
matchers and mocks to avoid testing unrelated implementation details.Testing Instructions
Verify tests pass:
npm run test:unit packages/editor/src/components/post-publish-button/test/index.js