[Bug]: Stackoverflow in toMatchObject when matching w/ recursive object
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
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.
We should start by adding a warning to the docs I guess, but it would be nice to support this
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.
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.
https://github.com/jestjs/jest/releases/tag/v30.0.0-alpha.4