Components: Refactor Tooltip tests to @testing-library/react#43061
Components: Refactor Tooltip tests to @testing-library/react#43061
Tooltip tests to @testing-library/react#43061Conversation
|
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/reactTooltip tests to @testing-library/react
ciampo
left a comment
There was a problem hiding this comment.
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? 🤔 |
ciampo
left a comment
There was a problem hiding this comment.
Hey @t-hamano , thank you for working on this!
I've left more feedback, mostly focused on these changes:
- let's not use
fakeTimersandsetTimeout— we can usejest.advanceTimersByTimeinstead and have tests written in a much more linear fashion - let's always query the
buttons (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 usetooltipinstead
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. |
ciampo
left a comment
There was a problem hiding this comment.
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
enzymetests 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.jsVerify tests pass:
npm run test:unit ./packages/components/src/tooltip/test/index.jsScreenshots or screencast