Issues with testing running for 5 minutes are tests have passed
I have encountered an issue in the useActivity.test.tsx file that results in Jest tests hanging indefinitely after completion when running the command npm run test-ci, which executes the tests with the flags --ci --coverage --detectOpenHandles. This behavior leads to the "Jest did not exit one second after the test run completed" message. Upon investigation, it appears that the problem arises from my handling of asynchronous operations within the test cases.
Investigation Details
Test Behavior: The tests complete successfully in approximately 2 seconds when run normally; however, there is an extended waiting time of up to 5 minutes when executed with the npm run test-ci command. This indicates that there are unresolved asynchronous operations or pending promises, which I have not addressed properly in the test code.
Temporary Fix: I found that adding jest.useFakeTimers() resolves the issue, allowing the tests to complete and exit without hanging. This solution effectively prevents any pending operations from delaying the test completion.
CI-Specific Behavior: The issue is specific to running tests in a CI environment, as indicated by the flags --ci and --detectOpenHandles.
I have created a fork of the project at the following link: https://github.com/MertzAndreas/weekplan_help/tree/taskItem-mock
GitHub
GitHub - MertzAndreas/weekplan_help at taskItem-mock
Weekplanner for Giraf. Contribute to MertzAndreas/weekplan_help development by creating an account on GitHub.
0 Replies