{"schemaVersion":"1.0","canonicalUrl":"https://automationtester.in/failures/jest-cannot-log-after-tests","slug":"jest-cannot-log-after-tests","title":"Jest cannot log after tests are done","signature":"Cannot log after tests are done. Did you forget to wait for something async","frameworks":["Jest"],"classification":"timing-race","summary":"Asynchronous work continued after Jest considered the test complete and attempted to write output later.","causes":[{"title":"A promise was not returned or awaited","explanation":"The test function ends before the asynchronous branch settles.","diagnostic":"Find unawaited calls and callbacks that create promises in the failing test.","fix":"Return or await the promise and assert after it resolves."},{"title":"A timer or subscription was not cleaned up","explanation":"Intervals, event listeners, or observers remain active after teardown.","diagnostic":"Run with open-handle detection and inspect created timers and subscriptions.","fix":"Clear timers and unsubscribe in afterEach or the component cleanup path."},{"title":"A mocked callback fires after teardown","explanation":"The mock schedule outlives the test's expected lifecycle.","diagnostic":"Inspect fake timers, delayed callbacks, and pending request mocks.","fix":"Flush the intended work or cancel it before restoring mocks."}],"prevention":["Await every async user journey.","Clean up timers and subscriptions.","Treat open handles as test failures."],"related":["unhandled-promise-rejection","playwright-timeout-exceeded"],"references":[{"label":"Jest asynchronous testing","url":"https://jestjs.io/docs/asynchronous"}]}