-
Notifications
You must be signed in to change notification settings - Fork 1.3k
test: fix flaky tests for focus and location mutation #944
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
Conversation
This pull request is automatically built and testable in CodeSandbox. To see build info of the built libraries, click here or the icon next to each commit SHA. Latest deployment of this branch, based on commit 8d0032f:
|
891e0b4
to
cd0e71d
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.
Looks great, thank you!
It might be a nitpick, but I think the name (But it’s just a suggestion and will not block the PR, so I’ll merge this one for now 👍. Thanks!) |
Thank you! |
Fixes #940
I've inspected why the focus tests are flaky.
I've found that some tests didn't wait for a deduping interval, which means that a mutation in the next test might be deduped and failed.
To fix this, I've added
await act(() => sleep(1))
before the next mutation. But the intention of the code is very unclear, so I've separated it as another function calledwaitForDedupingInterval
.In addition, many of the current tests depend on a real timer, which makes tests flaky, so I've refactored to avoid depending on a real timer as much possible as I can by using
screen.findByText
.I've also noticed that a test in
use-swr-local-mutation.test.tsx
is flaky, so I've fixed it too.I think there are more flaky tests in SWR, so I'll fix them so that tests are more reliable. #932 and #933 are PRs for it.