vitest-dev / vitest-dev/vitest
`toEqual` behavior with symbol properties with undefined 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
The behavior of toEqual with objects with symbol properties and undefined values is inconsistent with the behavior of toEqual with objects with regular (non-symbol) properties and undefined values.
With regular properties, undefined is treated as equivalent to not present, so expect({ a: undefined }).toEqual({}) passes. With symbol properties, they're not equivalent, so expect({ [sym]: undefined}).toEqual({}) fails.
The discrepancy appears to be caused by this logic: keys() checks hasKey (which defaults to hasDefinedKey - i.e., not undefined) for enumerable string properties but omits it for symbol properties.
I can submit a PR if there's interest.
Reproduction
System Info
System:
OS: macOS 15.5
CPU: (10) arm64 Apple M1 Pro
Memory: 155.73 MB / 16.00 GB
Shell: 5.9 - /bin/zsh
Binaries:
Node: 22.17.1 - ~/.nvm/versions/node/v22.17.1/bin/node
Yarn: 4.9.2 - /opt/homebrew/bin/yarn
npm: 10.9.2 - ~/.nvm/versions/node/v22.17.1/bin/npm
bun: 1.2.19 - /opt/homebrew/bin/bun
Browsers:
Chrome: 138.0.7204.169
Edge: 138.0.3351.95
Safari: 18.5
Safari Technology Preview: 26.0
npmPackages:
vitest: ^3.2.4 => 3.2.4
Used Package Manager
yarn
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 in packages/expect/src/jest-utils.ts around line 283 and run the StackBlitz reproduction to confirm the difference between symbol and regular properties with undefined values. Done means toEqual treats equivalent symbol-property cases consistently, with regression coverage for the reported behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- testing-qa
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 52/100