-
Notifications
You must be signed in to change notification settings - Fork 63
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
Fix Copyable tooltip spec #2519
Conversation
|
await waitFor(() => expect(getByText('Copied!')).toBeVisible()); | ||
const tooltip = getByText('Copied!'); | ||
|
||
// Tooltip should remain visible for a while | ||
await waitFor(() => expect(tooltip).toBeVisible()); | ||
|
||
await new Promise(resolve => setTimeout(resolve, 1000)); | ||
expect(getByText('Copied!')).toBeVisible(); | ||
|
||
// Tooltip should eventually disappear | ||
await waitForElementToBeRemoved(() => queryByText('Copied!')); | ||
await waitFor(() => expect(tooltip).not.toBeVisible()); |
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 does slightly alter how we're testing, but I think the most important thing is still tested which is that the tooltip appears and disappears after some time. Open to feedback if this warrants a different approach
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.
Curious, do we know what was causing the flakiness? I would feel like switching
await new Promise(resolve => setTimeout(resolve, 1000));
to
await waitFor(() => expect(getByText('Copied!')).toBeVisible());
alone would have fixed the test since it was failing on line 120 and not on line 123. I'm wondering why 123 needs a change at all?
Also curious, why are we waiting for 1 second on line 119/121?
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.
What currently happens is:
- user clicks and tooltip opens
useEffect
closes tooltip after 1500ms
The first line change fixes the flake:
await waitFor(() => expect(getByText('Copied!')).toBeVisible());
Consequently, the second line was breaking because it was timing out while waiting for the element to be removed which is why I left in line 119/121
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 replaced the duration with a constant and used it in the test. Open to feedback on writing the spec better
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 wonder if it would be better to just lengthen the waitFor
timeout. If it's just an early timeout, I believe that should solve it without the need for pausing execution entirely.
await waitFor(
() => expect(tooltip).not.toBeVisible(),
{ timeout: TOOLTIP_VISIBLE_DURATION } // or more if necessary?
);
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.
updated!
Size Change: 0 B Total Size: 1.39 MB ℹ️ View Unchanged
|
6e05093
to
979fa9f
Compare
979fa9f
to
4f3ac42
Compare
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.
✍️ Proposed changes
Fixes flaky test