jest
Event listener leak in Jest tests
MaxListenersExceededWarning.*test|memory leak.*detected.*test
Fixes
- 1.Remove event listeners in afterEach or component cleanup
- 2.Use --detectOpenHandles flag to identify what's keeping tests alive
- 3.Ensure server/socket connections opened in tests are closed in afterAll
jestmemory-leakcleanup
Related Errors
jest3 fixes
Jest assertion value mismatch
expect\(received\)\.toBe\(expected\)|Expected.*Received
- •Check expected vs actual values — use .toEqual() for objects instead of .toBe()
- •For floating point, use .toBeCloseTo() instead of exact equality
jest3 fixes
Jest mock function not called as expected
Expected.*mock.*to have been called|not been called|toHaveBeenCalled
- •Verify the mock is injected correctly — check the module path in jest.mock()
- •Ensure the code path that calls the function is actually reached
jest3 fixes
Jest async test timeout
Exceeded timeout.*Async callback|exceeded.*5000.*ms|jest.*timeout
- •Ensure async functions resolve: await the promise or call done()
- •Increase timeout: jest.setTimeout(10000) or third arg to it()