fix(expect-utils): handle cross-realm constructors in toStrictEqual#15959
Open
JamieMagee wants to merge 1 commit intojestjs:mainfrom
Open
fix(expect-utils): handle cross-realm constructors in toStrictEqual#15959JamieMagee wants to merge 1 commit intojestjs:mainfrom
JamieMagee wants to merge 1 commit intojestjs:mainfrom
Conversation
✅ Deploy Preview for jestjs ready!Built without sensitive environment variables
To edit notification comments on pull requests, go to your Netlify project configuration. |
|
|
babel-jest
babel-plugin-jest-hoist
babel-preset-jest
create-jest
@jest/diff-sequences
expect
@jest/expect-utils
jest
jest-changed-files
jest-circus
jest-cli
jest-config
@jest/console
@jest/core
@jest/create-cache-key-function
jest-diff
jest-docblock
jest-each
@jest/environment
jest-environment-jsdom
@jest/environment-jsdom-abstract
jest-environment-node
@jest/expect
@jest/fake-timers
@jest/get-type
@jest/globals
jest-haste-map
jest-jasmine2
jest-leak-detector
jest-matcher-utils
jest-message-util
jest-mock
@jest/pattern
jest-phabricator
jest-regex-util
@jest/reporters
jest-resolve
jest-resolve-dependencies
jest-runner
jest-runtime
@jest/schemas
jest-snapshot
@jest/snapshot-utils
@jest/source-map
@jest/test-result
@jest/test-sequencer
@jest/transform
@jest/types
jest-util
jest-validate
jest-watcher
jest-worker
pretty-format
commit: |
1307f20 to
2870469
Compare
structuredClone returns objects whose constructors come from the outer VM context. typeEquality and iterableEquality compared constructors by identity (===), which always failed across realms — even for plain objects, Maps, Sets, Dates, and RegExps. When constructors don't match by identity, fall back to comparing constructor names, but only when both are native built-in functions. User-defined classes still require identity equality, so toStrictEqual keeps distinguishing e.g. two different classes named Child. Fixes jestjs#14011
2870469 to
ecb0380
Compare
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.
Summary
structuredCloneruns in the outer Node.js realm, so its return values have different constructor references than objects created inside Jest's VM context. This madetoStrictEqualfail with "serializes to the same string" for every built-in type (plain objects, Maps, Sets, Dates, RegExps).When constructors don't match by identity, we now check if both are native built-ins with the same name. User-defined classes still require identity equality.
Changed
typeEqualityanditerableEqualityinexpect-utils/src/utils.ts.Fixes #14011
Test plan
10 unit tests added using
vm.createContext()to create cross-realm objects. Covers all affected built-in types, plus a negative case for user-defined classes with the same name.