Skip to content

Conversation

@hi-ogawa
Copy link
Contributor

@hi-ogawa hi-ogawa commented Jan 27, 2026

Description

Resolves #9522

toMatchObject was loose since subsetEquality treats Map/Set as empty object. This feels like an unexpected behavior since builtin iterableEquality is already aware of Map/Set and for example, toMatchObject supports deeply asserting shapes when Map/Set appears at the same nested level (so, subset equality works inside Set/Map test added here already passes before this PR).

I found there is also relatively recent change on Jest jestjs/jest#14873 jestjs/jest#14599, which get addressed with same fix.

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.
  • Please check Allow edits by maintainers to make review process faster. Note that this option is not available for repositories that are owned by Github organizations.

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:.

`toMatchObject` was incorrectly passing when comparing plain objects
against Map/Set because `isObjectWithKeys` didn't exclude these types.
This caused `Object.keys()` to return an empty array, making
`[].every()` trivially return true.

Fixes vitest-dev#9522

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@netlify
Copy link

netlify bot commented Jan 27, 2026

Deploy Preview for vitest-dev ready!

Built without sensitive environment variables

Name Link
🔨 Latest commit ff51af7
🔍 Latest deploy log https://app.netlify.com/projects/vitest-dev/deploys/69785d5b60bf750008d0e8dc
😎 Deploy Preview https://deploy-preview-9532--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.

@hi-ogawa hi-ogawa marked this pull request as ready for review January 27, 2026 07:10
@sheremet-va sheremet-va merged commit 381da4a into vitest-dev:main Jan 27, 2026
13 of 16 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.

Testing expect(null).toMatchObject(...) against a Map or Set should fail

2 participants