Testing & Debugging Errors
50 errors
Common testing & debugging errors and how to fix them.
50 / 50
- 1
AssertionError: Expected values to be equal
The most common test failure: your assertion expected one value but got another. The error message shows both values to help you diagnose the mismatch.
- 2
TypeError: jest.fn is not a function
The test tries to use jest.fn() but Jest is not available in the current environment. This happens when the test runner isn't Jest or Jest isn't configured.
- 3
Async Test Not Awaiting Promise
The test function returns before the async operation completes. Jest marks the test as passed without running the assertions, giving a false positive.
- 4
Snapshot Mismatch
The output of your code changed since the snapshot was last saved. This could be an intentional change or a bug — you need to review the diff.
- 5
Test Timeout Exceeded
The test didn't finish within the timeout period. This usually means an async operation is hanging or the test is doing too much work.
- 6
Mock Not Called
The assertion toHaveBeenCalled() failed because the mock was never called. Your code path didn't trigger the expected function call.
- 7
Cannot Find Module
Jest can't find the module you're trying to import. The path might be wrong, the file might not exist, or Jest's module resolution isn't configured correctly.
- 8
ReferenceError: describe is not defined
The test uses Jest globals (describe, test, expect) but they're not defined. Jest is either not the test runner or globals aren't configured.
- 9
Coverage Below Threshold
Your test suite passes, but coverage is below the configured threshold. New code was added without sufficient tests.
- 10
Spy Not Restored
A spy replaced a real function but was never restored, so the spy persists into other tests, causing unexpected behavior.
- 11
Expected to Throw but Did Not
The test expected the code to throw an error, but it didn't. Either the code should throw but doesn't (a bug), or the test expectation is wrong.
- 12
toBe Used on Object (Reference Inequality)
toBe uses Object.is (reference equality). Two separately created objects are different references, so toBe fails even for identical content. Use toEqual for deep equality.
- 13
Test Not Running (File Not Discovered)
Jest can't find your test files. The files might not match Jest's naming convention or the testMatch config is wrong.
- 14
Unhandled Promise Rejection in Test
An async operation rejected (threw an error) but the test didn't catch it. This can cause the test to pass incorrectly or crash unexpectedly.
- 15
Mock Implementation Incorrect
The mock's return value doesn't match what the test expects. The mock setup (mockReturnValue, mockResolvedValue) has the wrong value.
- 16
Floating Point Comparison Failure
JavaScript floating-point arithmetic is imprecise. 0.1 + 0.2 equals 0.30000000000000004, not 0.3. Using toBe for exact comparison fails.
- 17
Test Order Dependency
The test depends on state left by other tests. When run alone it sets up its own state, but in the full suite, previous tests have modified shared state.
- 18
Cannot Read Property of Undefined
The code or test tries to access a property on an undefined value. A mock might not be configured to return the expected object.
- 19
Missing done() Callback in Async Test
The test uses the done callback pattern but forgets to call done() inside the async callback. Jest marks the test as complete before the assertion runs.
- 20
No Assertions in Test
The test completed without calling expect(). Without assertions, the test always passes — even if the code is completely broken.
- 21
toMatchObject Partial Match Failure
toMatchObject checks that the received object contains at least the expected properties with matching values. A property value didn't match.
- 22
Fake Timer Not Restored
Fake timers were enabled but never restored to real timers, causing time-related issues in subsequent tests.
- 23
Enzyme Method Not Found (React Testing)
The test uses Enzyme APIs (find, simulate, shallow) but Enzyme is not installed, not configured, or the method doesn't exist on the wrapper.
- 24
Element Not Found in DOM Test
The test tries to find an element (by role, text, testId) but it doesn't exist in the rendered component. The element might not be rendered or the query is wrong.
- 25
Multiple Elements Found
The query found more than one element. getBy* queries must find exactly one match — use getAllBy* for multiple matches.
- 26
Test File Syntax Error
The test file contains a syntax error — a typo, missing bracket, or unsupported syntax. Jest can't parse and run the file.
- 27
Circular Reference in Snapshot
The object passed to toMatchSnapshot() has a circular reference (an object that references itself), which can't be serialized.
- 28
E2E Test Timeout Waiting for Element
The E2E test waited for an element that never appeared within the timeout. The page might not have loaded, or the element doesn't exist.
- 29
Jest Configuration Error
jest.config.js or the Jest config in package.json has an invalid setting, causing Jest to fail before running any tests.
- 30
Memory Leak in Long Test Suite
The test suite consumes too much memory, causing Node.js to crash with an out-of-memory error. This happens with very large test suites or memory leaks.
- 31
Test timeout: async test did not complete
Your test timed out — an async operation or promise did not resolve or reject within the timeout period.
- 32
Mock not called: expected interaction did not happen
Your test expects a mock to be called but the code path did not trigger the mocked function.
- 33
Fixture not found: test data file missing
Your test tries to load a fixture file but the file is not found at the specified path.
- 34
Test isolation failure: shared state between tests
Your tests share state — one test modifies data that affects another test's outcome depending on execution order.
- 35
Snapshot mismatch: UI or output changed
Your snapshot test fails — the output changed from the stored snapshot, which may be an intentional change or a regression.
- 36
Unhandled promise rejection in test
Your test has an unhandled promise rejection — a promise was rejected but no .catch() or try/catch handled it.
- 37
Memory leak in long-running test suite
Your test suite leaks memory — objects, listeners, or connections accumulate and are not cleaned up between tests.
- 38
Missing test decorator or annotation
Your test function is not recognized by the test runner — it is missing the @test decorator or test() wrapper.
- 39
Invalid assertion: matcher does not exist
Your test uses a matcher like toBeGreaterThan or toMatchSnapshot that the test framework does not recognize.
- 40
Type mismatch in test assertion
Your assertion compares values of different types — the matcher cannot compare a string with a number, for example.
- 41
Missing import in test file
Your test uses a function or class that is not imported — the test fails with a ReferenceError at runtime.
- 42
Invalid test configuration: unknown option
Your test config has an unknown option — the test framework rejects the configuration or ignores the option.
- 43
Circular dependency in test setup
Your test setup has circular imports — module A imports module B which imports module A, causing incomplete initialization.
- 44
Flaky test: passes and fails intermittently
Your test is flaky — it sometimes passes and sometimes fails due to non-deterministic behavior.
- 45
Testing implementation instead of behavior
Your test checks how the code works internally rather than what it does — refactoring breaks the test even if behavior is unchanged.
- 46
Insufficient test coverage: missing edge cases
Your tests only cover the typical case — edge cases, error paths, and boundary values are not tested.
- 47
Over-mocking: test tests the mock not the code
Your test mocks so much that it tests the mock setup rather than the actual code under test.
- 48
Assertion without message: unclear failure
Your assertion failed but the error message is generic — it is unclear what was expected and what was received.
- 49
Test depends on environment: fails on CI but not locally
Your test passes on your machine but fails in CI — it depends on environment-specific settings or resources.
- 50
Unused test setup: beforeEach without cleanup
Your beforeEach creates resources but there is no afterEach to clean up — subsequent tests are affected by leftover state.
No errors found.