Bun "expect(received).toBe(expected)" assertion failure in CI
A bun:test matcher reported that the received value does not equal the expected value. The failure block shows both sides and a diff so you can see exactly what differed.
What this error means
bun test prints an "(fail)" block with "expect(received).toBe(expected)" (or toEqual, toContain) and a colored diff of the two values.
Terminal
(fail) format > formats currency
error: expect(received).toBe(expected)
Expected: "$1,000.00"
Received: "$1000"Common causes
The code produces a different value than asserted
A logic change or an environment difference (locale, rounding) makes the received value diverge from the expectation.
A strict matcher on a structurally-equal value
Using toBe (reference equality) where toEqual (deep equality) is meant fails on two equal-but-distinct objects.
How to fix it
Compare expected and received, then fix one side
- Read the Expected and Received values in the fail block.
- Decide whether the code or the expectation is wrong.
- Fix the logic, or update the expectation if the new value is correct.
src/format.test.ts
import { expect, test } from "bun:test";
test("formats currency", () => {
expect(formatCurrency(1000)).toBe("$1,000.00");
});Use the right matcher for the value
Use toEqual for deep structural comparison of objects and arrays instead of toBe reference equality.
src/format.test.ts
expect(result).toEqual({ total: 1000, currency: "USD" });How to prevent it
- Pick toEqual for structural comparisons, toBe for primitives/refs.
- Make formatting deterministic (fixed locale/timezone) in tests.
- Assert on stable, normalized values.
Related guides
Bun "test failed" nonzero exit code (bun test) in CIFix `bun test` failing CI - one or more tests failed, so bun test exits nonzero and fails the job. Read the f…
Bun test "ENOENT" reading a fixture / file in CIFix "ENOENT: no such file or directory" during bun test in CI - a test reads a fixture by a path that does no…
Bun "TypeError: X is not a function" (Node API gap) in CIFix Bun "TypeError: X is not a function" in CI - a Node.js API a dependency calls is not implemented (or diff…