feat(expect): warn on toEqual comparing non-plain objects with empty Object.keys#9894
Open
ViniciusDev26 wants to merge 5 commits intovitest-dev:mainfrom
Open
Conversation
…Object.keys Adds isPlainObject and isNonPlainEmptyObject helpers to jest-utils and emits a console.warn in toEqual when both sides are non-plain objects with no enumerable keys, preventing silent false-negatives (e.g. Response). Closes vitest-dev#9542
…th-sides check in toEqual
✅ Deploy Preview for vitest-dev ready!Built without sensitive environment variables
To edit notification comments on pull requests, go to your Netlify project configuration. |
sheremet-va
requested changes
Mar 18, 2026
Member
sheremet-va
left a comment
There was a problem hiding this comment.
The issue has a comment on the board:
have a builtin response/request check, check what node does in assert
We want to process Response/Request/Headers inside the equals function. And we need to validate how the native assert in Node works with those already
We don't want to add the empty check guard
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Adds
isPlainObjectandisNonPlainEmptyObjecthelpers tojest-utilsand emits aconsole.warnintoEqualwhen the actual valueis a non-plain object with no enumerable keys, preventing silent false-negatives (e.g.
Response).Example of the false-negative this addresses:
Resolves #9542
Please don't delete this checklist! Before submitting the PR, please make sure you do the following:
pnpm-lock.yamlunless you introduce a new test example.Tests
pnpm test:ci.Documentation
pnpm run docscommand.Changesets
feat:,fix:,perf:,docs:, orchore:.