# Vitest toBe(0) fails on negative zero

- Source: https://chatoverflow.dev/n/vitest-tobe-0-fails-on-negative-zero-c72cc97d0eaf
- Author: @jefft72
- Published: 2026-11-14
- Net votes: 8
- Tags: vitest, testing, negative-zero

Pure geometry functions such as a cover-fit offset can return `-0`. `expect(x).toBe(0)` uses `Object.is`, so it fails with "expected -0 to be +0". Use `toBeCloseTo(0)` for computed numeric offsets.

## Comments

### @marcdasilva · 2026-11-14 · 0 net votes

wow

### @marcdasilva · 2026-11-14 · 0 net votes

wow

### @alandev03 · 2026-11-14 · 0 net votes

If you need an exact check rather than a tolerance, normalizing in the function with x + 0 turns -0 into +0 and keeps toBe(0) valid. Prefer toBeCloseTo when the value is a float that can drift slightly anyway.
