vitest-dev / vitest-dev/vitest
Vitest considers `-0` and `+0` to be different values
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 17.1k
- Forks
- 2k
- Avg merge
- 1d 22h
- Merged PRs (30d)
- 94
Description
Describe the bug
I have a utility that may return -0.
This is technically a distinct value from +0, but per IEEE_754, "negative zero" and "positive zero" should be considered to be equal in numerical comparisons.
But vitest's .toBe() and .toEqual() methods appears to not consider them to be equal, causing unit tests to fail.
Reproduction
https://stackblitz.com/edit/vitest-dev-vitest-dgy7dtwc?file=test%2Fbasic.test.ts
System Info
The issue is reproduced in StackBlitz above, but here is my system info.
System:
OS: Linux 6.8 Ubuntu 22.04.4 LTS 22.04.4 LTS (Jammy Jellyfish)
CPU: (20) x64 13th Gen Intel(R) Core(TM) i5-13600K
Memory: 19.04 GB / 31.12 GB
Container: Yes
Shell: 5.8.1 - /bin/zsh
Binaries:
Node: 20.13.1 - ~/.nvm/versions/node/v20.13.1/bin/node
Yarn: 1.22.22 - ~/.nvm/versions/node/v20.13.1/bin/yarn
npm: 10.5.2 - ~/.nvm/versions/node/v20.13.1/bin/npm
pnpm: 8.15.9 - ~/.nvm/versions/node/v20.13.1/bin/pnpm
npmPackages:
@vitejs/plugin-react-swc: ^3.8.0 => 3.8.0
@vitest/coverage-v8: ^3.0.6 => 3.0.6
@vitest/ui: ^3.0.6 => 3.0.6
vite: ^6.1.0 => 6.1.0
vitest: ^3.0.6 => 3.0.6
Used Package Manager
pnpm
Validations
- Follow our Code of Conduct
- Read the Contributing Guidelines.
- Read the docs.
- Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.
- Check that this is a concrete bug. For Q&A open a GitHub Discussion or join our Discord Chat Server.
- The provided reproduction is a minimal reproducible example of the bug.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the linked StackBlitz reproduction and trace the matcher implementations for .toBe() and .toEqual(). Add or update coverage for -0 and +0, with both matchers treating them as equal when the tests are complete.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- testing-qa
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100