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

RangeError: Maximum call stack size exceeded when toMatchObject with array circular references #5538

Closed
6 tasks done
hi-ogawa opened this issue Apr 14, 2024 · 1 comment · Fixed by #5535
Closed
6 tasks done
Labels
p3-minor-bug An edge case that only affects very specific usage (priority)

Comments

@hi-ogawa
Copy link
Contributor

Describe the bug

Similar to #5533, but the cause of the issue looks slightly different, so I'm creating a separate issue.

The failing case is taken from Jest's issue:

import { test, expect } from 'vitest';

function gen() {
  const a: any = {
    v: 1,
  };
  const c1: any = {
    ref: [],
  };
  c1.ref.push(c1);
  a.ref = c1;
  return a;
}

// success
test('toEqual', () => {
  expect(gen()).toEqual(gen()); 
});

// RangeError: Maximum call stack size exceeded
test('toMatchObject', () => {
  expect(gen()).toMatchObject(gen()); 
});

Reproduction

https://stackblitz.com/edit/vitest-dev-vitest-ysdtzj?file=test%2Frepro.test.ts

System Info

[stackblitz]

  System:
    OS: Linux 5.0 undefined
    CPU: (8) x64 Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz
    Memory: 0 Bytes / 0 Bytes
    Shell: 1.0 - /bin/jsh
  Binaries:
    Node: 18.18.0 - /usr/local/bin/node
    Yarn: 1.22.19 - /usr/local/bin/yarn
    npm: 10.2.3 - /usr/local/bin/npm
    pnpm: 8.15.3 - /usr/local/bin/pnpm
  npmPackages:
    @vitest/ui: latest => 1.5.0 
    vite: latest => 5.2.8 
    vitest: latest => 1.5.0

Used Package Manager

npm

Validations

@hi-ogawa hi-ogawa added pending triage p3-minor-bug An edge case that only affects very specific usage (priority) and removed pending triage labels Apr 14, 2024
@hi-ogawa
Copy link
Contributor Author

hi-ogawa commented Apr 16, 2024

In some cases, chai's utils.getMessage after jestEquals is also getting into loop:

const pass = jestEquals(actual, expected, [...customTesters, iterableEquality, subsetEquality])
const isNot = utils.flag(this, 'negate') as boolean
const { subset: actualSubset, stripped } = getObjectSubset(actual, expected)
const msg = utils.getMessage(
this,
[
pass,
'expected #{this} to match object #{exp}',
'expected #{this} to not match object #{exp}',
expected,
actualSubset,
],
)

@github-actions github-actions bot locked and limited conversation to collaborators May 2, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
p3-minor-bug An edge case that only affects very specific usage (priority)
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant