For the past few months my tests have been working perfectly. My package versions are fixed, not ranges, and we have not updated any dependency. However, since three days ago, the tests won't run at all. Jest just hangs in the [RUNS] myTests/file.spec.tsx
forever (I've waited more than 10 minutes).
I've got a timeout set to 10000ms (10s), but even reaching that timeout won't make the test to fail. It's like it's stuck before even starting to execute the tests.
This has been detected in a CI Pipeline, and after deleting node_modules
and re-installing again locally, it happens in my local environment, too.
After some troubleshooting, I've been able to reproduce it in a newly created test file, and it always happens when I add an expect accessing the DOM properties, such as toHaveStyle
:
const placeholder = screen.getByTestId('floating-placeholder');
expect(placeholder).toBeInTheDocument(); // This works
expect(placeholder).toHaveStyle({ top: '13px' }); // As soon as I write this line, the tests hangs forever
I don't know what to do because the only thing I can think of is library versions, but we haven't updated any of our dependencies in the last months. Furthermore, I've updated the versions of RTL (jest-dom, user-event, etc.) and Jest to test, and it hasn't worked.
Using the --verbose
flag in Jest script shows that the process is stuck in this line forever:
npm timing npm:load Completed in 42ms
(the "42ms" number changes very quickly all the time, like a chrono, but it never gets past there).
I've also looked for changes in libraries like jest-dom
and so on just in case some other library with peer dependencies could have updated it, but there's been no update either.
Application was created with the create-react-script
util.
What could I do to try to spot why is it failing all of a sudden?
Thank you!
Well, I don't know why it suddenly stopped working. I don't know why, either, this seems to fix it. But downgrading the version of @testing-library/jest-dom
from 5.16.4
to 5.16.3
and making a clean install seems to fix it, and now all tests are running in green, even in the CI pipeline.
The only difference in the changelog from these two versions is this single fix:
Support unenclosed inner text for details elements in to be visible (#396) (af18453)
Which should not affect at all at how the tests are behaving with this version in my project. But it seems, somehow, it does.