Skip to content

fix(core): Fix objectContaining expect utility to have more compatibility to jest's one #8241

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 3, 2025

Conversation

Shinyaigeek
Copy link
Contributor

@Shinyaigeek Shinyaigeek commented Jul 1, 2025

Description

Closes: #8170

As the above issue mentions, objectContaining cannot check equality of object which has symbol key correctly.
This is because the current implementation of objectContaining is based on simple iterator and Object.hasOwnProperty, and symbolic keys are not enumerated in simple iterator.

In jest's implementation(ref: https://github.com/jestjs/jest/blob/7250950f1385cff688bfef514ea50eb2ffa6495d/packages/expect-utils/src/utils.ts#L46-L57), this is considered so jest's objectContaining works fine with object which has symbol key.

This PR fixes #8170 and accomplish more compatibility of objectContaining expect utility to jest's one by adding Object.getOwnPropertySymbols and Object.hasOwn based property checking for symbol key consideration

Please don't delete this checklist! Before submitting the PR, please make sure you do the following:

  • It's really useful if your PR references an issue where it is discussed ahead of time. If the feature is substantial or introduces breaking changes without a discussion, PR might be closed.
  • Ideally, include a test that fails without this PR but passes with it.
  • Please, don't make changes to pnpm-lock.yaml unless you introduce a new test example.

Tests

  • Run the tests with pnpm test:ci.

Documentation

  • If you introduce new functionality, document it. You can run documentation with pnpm run docs command.

Changesets

  • Changes in changelog are generated from PR name. Please, make sure that it explains your changes in an understandable manner. Please, prefix changeset messages with feat:, fix:, perf:, docs:, or chore:.

Copy link

netlify bot commented Jul 1, 2025

Deploy Preview for vitest-dev ready!

Built without sensitive environment variables

Name Link
🔨 Latest commit 899acca
🔍 Latest deploy log https://app.netlify.com/projects/vitest-dev/deploys/686415b6a4de8e000872dd6b
😎 Deploy Preview https://deploy-preview-8241--vitest-dev.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@Shinyaigeek Shinyaigeek changed the title Fix objectContaining expect utility to have more compatibility to jest's one fix(core): Fix objectContaining expect utility to have more compatibility to jest's one Jul 1, 2025
@Shinyaigeek
Copy link
Contributor Author

hmm...some tests which seems not to be related to objectContaining are failing on CI...perhaps, are some of tests flaky?

@sheremet-va sheremet-va merged commit 480be1a into vitest-dev:main Jul 3, 2025
13 of 15 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

objectContaining is not considering Symbols
2 participants