Skip to content
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

Fix(expect-utils): Circular references not being caught when inside arrays #14894

Merged
merged 5 commits into from
Mar 16, 2024

Conversation

KhaledElmorsy
Copy link
Contributor

@KhaledElmorsy KhaledElmorsy commented Feb 11, 2024

Summary

As seen in issue #14734, when matching objects with toMatchObject(), circular references within arrays weren't caught and led to stack overflows.

This fixes the issue by adapting subsetEquality() in /expect-utils/utils, which is the main custom tester for toMatchObject()'s subset matching, to track visited objects instead of their members that are objects. It already had a method of catching circular references, but that only recorded object properties, while skipping arrays, and by extension, their elements.

Fixes #14734

Test plan

Added e2e tests ensuring that circular references in built in object types, namely arrays, sets, and maps, are matched correctly.

Copy link

netlify bot commented Feb 11, 2024

Deploy Preview for jestjs ready!

Name Link
🔨 Latest commit 054dbc6
🔍 Latest deploy log https://app.netlify.com/sites/jestjs/deploys/65f55843b7efa5000879221f
😎 Deploy Preview https://deploy-preview-14894--jestjs.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 site configuration.

@KhaledElmorsy KhaledElmorsy changed the title Fix circular references not being caught when inside arrays Fix: circular references not being caught when inside arrays Feb 22, 2024
@KhaledElmorsy KhaledElmorsy changed the title Fix: circular references not being caught when inside arrays Fix(expect-utils): Circular references not being caught when inside arrays Feb 22, 2024
Copy link
Member

@SimenB SimenB left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice fix, thanks!

@SimenB SimenB merged commit c872aa5 into jestjs:main Mar 16, 2024
7 of 9 checks passed
Copy link

This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
Please note this issue tracker is not a help forum. We recommend using StackOverflow or our discord channel for questions.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 16, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Bug]: Stackoverflow in toMatchObject when matching w/ recursive object
2 participants