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.
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.
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.