-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Test works in isolation but fails alongside other RTL-based tests #1346
Comments
I also have this issue after updating [email protected] The only solution I've found is to re-render after all user-event interactions...which is painful and I can't believe would be intended. Anyone else find a better solution? |
You can also disable fake timers and that seems to fix the issue for me...but I also don't like this solution. As long as userEvent is setup with |
Found two more things that work
|
You can also get around this issue by rendering with |
Hey @Aerophite, @johncornish any updates on this? Did you downgrade to a different version? |
@johncornish @Aerophite Can you please share a cloneable reproduction? Either a github repo or https://testing-library.com/new-rtl will help us to try and investigate this. |
@testing-library/react
version:"@testing-library/jest-dom": "^5.17.0",
"@testing-library/react": "^14.0.0",
"@testing-library/user-event": "^14.0.0",
Jest, maybe 29.5.12? Unknown version within Create React App (package-lock says "@types/jest": "^29.5.12",)
jsdom from jest-environment-jsdom 27.5.1
Relevant code or config:
What you did:
I have 10 unit tests that simulate a login with some fake API data (all data is contained in
beforeAll
), and then assert the default page for that type of user and what else they can navigate to. They each work individually, and they ought to, because I don't think I'm trying to do anything crazy--I'm not even trying to change the endpoints for each test, which I was doing before and which proved to be extremely finicky. I've isolated a stable subset of the fake API for each set of tests because I banged my head against the wall for a day with nonsensical failures when attempting to define different responses to the same endpoints within eachit(...)
block (for example, in one run there's one transaction, and in the next that endpoint returns[]
and the app should displayNo transactions found.
) I have some inkling to watch out for Jest test parallelization, so I've tried--runInBand
to no avail. I have been berated by warnings about how I have to wrap state changes inact()
, so I've tried doing that; at first it seemed like it helped, but then it just went back to failing. I figured somewhere I should be usingwaitFor
, but RTL documentation says that using thefind...
queries has that built in automatically. Interestingly, I can get the "problem test" to succeed by skipping the test before it, and I can change which test fails by moving them around, as if just the 5th or 6th test is doomed to fail.What happened:
The 5th test usually fails if run alongside the other tests. When it's run by itself, it works fine.
Reproduction:
Problem description:
It's seemingly so arbitrary. I've meticulously scoured the documentation and many, many Stack Overflow posts and I just can't reason about why it's behaving so erratically.
Suggested solution:
Document how to do this type of testing because the current learning curve is immensely steep.
The text was updated successfully, but these errors were encountered: