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

[Bug]: Stackoverflow in toMatchObject when matching w/ recursive object #14734

Closed
connorjclark opened this issue Dec 1, 2023 · 5 comments · Fixed by #14894
Closed

[Bug]: Stackoverflow in toMatchObject when matching w/ recursive object #14734

connorjclark opened this issue Dec 1, 2023 · 5 comments · Fixed by #14894

Comments

@connorjclark
Copy link
Contributor

connorjclark commented Dec 1, 2023

Version

29.7.0

Steps to reproduce

Using expect 29.7.0

Here is a contrived example (real usage here / here)

const a = {
  v: 1,
};
const b = {
  v: 1,
};
const c1 = {
  ref: [],
};
c1.ref.push(c1);
const c2 = {
  ref: [],
};
c2.ref.push(c2);

a.ref = c1;
b.ref = c2;
expect(a).toMatchObject(b);

Expected behavior

Either document that recursive objects are not supported, or support them.

Actual behavior

RangeError: Maximum call stack size exceeded

Additional context

No response

Environment

n/a
Copy link

github-actions bot commented Jan 1, 2024

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 30 days.

@SimenB
Copy link
Member

SimenB commented Jan 2, 2024

We should start by adding a warning to the docs I guess, but it would be nice to support this

@KhaledElmorsy
Copy link
Contributor

KhaledElmorsy commented Feb 9, 2024

As far as I've tested, the issue doesn't happen if the circular reference is not in an array nor if it's in a set. It also works if it's nested deeper in. I can take a crack at fixing this issue if no one else is working on it.

Copy link

This issue 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
@SimenB
Copy link
Member

SimenB commented May 12, 2024

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants