jest icon indicating copy to clipboard operation
jest copied to clipboard

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

Open connorjclark opened this issue 2 years ago • 3 comments

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

connorjclark avatar Dec 01 '23 23:12 connorjclark

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.

github-actions[bot] avatar Jan 01 '24 00:01 github-actions[bot]

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

SimenB avatar Jan 02 '24 08:01 SimenB

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.

KhaledElmorsy avatar Feb 09 '24 15:02 KhaledElmorsy

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[bot] avatar Apr 16 '24 00:04 github-actions[bot]

https://github.com/jestjs/jest/releases/tag/v30.0.0-alpha.4

SimenB avatar May 12 '24 21:05 SimenB