Node AssertionError in CI - Fix the Failed Invariant
An AssertionError is thrown when an assert call fails. It marks a violated invariant: the actual value did not match what the code asserted must be true.
What this error means
A node process or test throws AssertionError [ERR_ASSERTION] with expected and actual values, then exits non-zero because an assert condition was false.
node
AssertionError [ERR_ASSERTION]: Expected values to be strictly equal:
2 !== 3
at Object.<anonymous> (/home/runner/work/app/app/test/sum.test.js:4:8) {
code: 'ERR_ASSERTION', expected: 3, actual: 2, operator: 'strictEqual'
}Common causes
The code under test produced the wrong value
A real bug makes the actual result diverge from the asserted expectation.
The assertion encodes a stale expectation
Behavior changed intentionally but the assert still checks the old value.
How to fix it
Fix the code so the invariant holds
- Read the expected vs actual values in the error.
- Correct the logic so the actual matches the assertion.
Update the assertion if the expectation changed
- Confirm the new behavior is intended.
- Adjust the asserted value to the correct expectation.
JavaScript
assert.strictEqual(sum(1, 2), 3);How to prevent it
- Keep assertions in sync with intended behavior, give them clear messages, and run the assertion path locally so failed invariants surface before CI.
Related guides
Node "process.exit called with code 1" Fails the Job in CI - Trace the CauseFix CI jobs failing on a Node.js process.exit(1) by finding the deliberate exit call and addressing the condi…
Node "Timeout - Async callback was not invoked" in CI - Fix the Hanging TestFix the "Timeout - Async callback was not invoked within the timeout" test error in CI by resolving the pendi…
Node ERR_INTERNAL_ASSERTION in CI - Diagnose the Internal FailureDiagnose the Node.js ERR_INTERNAL_ASSERTION error in CI by upgrading Node, removing the misbehaving native ad…