vitest-dev / vitest-dev/vitest

`toEqual` behavior with symbol properties with undefined values

Open
#8,342 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

pending triage
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

https://stackblitz.com/edit/vitest-dev-vitest-ttuzge3r?file=test%2Fbasic.test.ts,package.json&initialPath=__vitest__

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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.