Skip to content

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

@connorjclark

Description

@connorjclark

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions