-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Components: Refactor Tooltip
tests to @testing-library/react
#43061
Conversation
Size Change: +149 B (0%) Total Size: 1.24 MB
ℹ️ View Unchanged
|
I'd love to, but currently don't have the capacity to work on it systematically. We're trying to chip at it when we can as part of other work on components — but I know that @tyxla has been working on the switch to RTL too! |
@ciampo, processing 60 files isn't a simple effort. I feel you 😄 Anyway, if someone wants to champion the coordination process that would be ace! |
The existing test passed, but I was looking for any other tests needed. |
Tooltip
tests to @testing-library/react
Tooltip
tests to @testing-library/react
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.
Thank you @t-hamano for your work and @tyxla for your help in reviewing!
I left a few comments, but from my point of view a lot of these tests are very implementation details-focuses. I'd be tempted to determine a new list of what we should be testing for Tooltip
based on user behavior and interactions (WDYT, @mirka ?)
Looking at these tests, I'm starting to realize that our current implementation is missing a I wanted to mention this now because I think it means we have less pressure to write a perfectly comprehensive set of tests here, since it's unlikely we'd be able to bulk replace the existing Tooltip usage anyway. (Sidenote: These RTL refactors are quickly exposing semantic gaps in our components, which is great 😄) |
I removed |
Thanks for the detailed review 😊 I would further suggest the following improvements, does this make sense? Use meaningful button names
Test name standardizationUnify Don't use settimeoutI am not sure if this is the correct way to do it, it looks like it could be rewritten simply as follows: jest.useFakeTimers();
setTimeout( () => {
expect( screen.getByText( 'Help text' ) ).toBeInTheDocument();
jest.runOnlyPendingTimers();
jest.useRealTimers();
}, TOOLTIP_DELAY );
// to...
act( () => jest.advanceTimersByTime( TOOLTIP_DELAY ) );
expect( screen.getByText( 'Help text' ) ).toBeInTheDocument(); If the latter implementation is a real timer instead of a fake timer, is there a performance problem? 🤔 |
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.
Hey @t-hamano , thank you for working on this!
I've left more feedback, mostly focused on these changes:
- let's not use
fakeTimers
andsetTimeout
— we can usejest.advanceTimersByTime
instead and have tests written in a much more linear fashion - let's always query the
button
s (and the DOM in general) by specifying the expected accessiblename
- let's merge similar tests, and remove redundant ones
- let's not pass the same mock function for two separate callbacks
- let's not use the term
popover
, as it hints at an internal implementation detail — let's usetooltip
instead
Can you add an entry to the CHANGELOG under the "Internal" section?
Thank you!
…' test without and
…re the tooltip has shown
I appreciate your painstaking review. Note that the test command has changed because trunk was merged.
|
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.
Can we add a CHANGELOG entry under the Internal
section ?
Apart from that, this PR is in a great spot and we can merge as soon as the CHANGELOG entry is added and all tests are ✅
Done 🚀 |
Thank you! This PR definitely improved |
Part of #42753
What?
Refactoring of the Tooltip component is being considered in #42753.
As a first step, I rewritten tests to
@testing-library/react
.How?
I straightforwardly replacd
enzyme
tests with@testing-library/react
, with a few exceptions, based on the following post:Testing Instructions
Verify tests pass:npm run test-unit ./packages/components/src/tooltip/test/index.js
Verify tests pass:
npm run test:unit ./packages/components/src/tooltip/test/index.js
Screenshots or screencast