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

Cannot test object with multiple circular references #5533

Closed
6 tasks done
qmhc opened this issue Apr 13, 2024 · 1 comment · Fixed by #5535
Closed
6 tasks done

Cannot test object with multiple circular references #5533

qmhc opened this issue Apr 13, 2024 · 1 comment · Fixed by #5535
Labels
p3-minor-bug An edge case that only affects very specific usage (priority)

Comments

@qmhc
Copy link

qmhc commented Apr 13, 2024

Describe the bug

When using expect.toEqual or expect.toMatchObject to test a object that with multiple circular references, it will make maximum call stack size exceeded error.

PS: It works in v1.1.3.

Reproduction

https://stackblitz.com/edit/vitest-dev-vitest-qd5xyk?file=test%2Fsuite.test.ts&view=editor

System Info

System:
  OS: Windows 11 10.0.22631
  CPU: (20) x64 12th Gen Intel(R) Core(TM) i7-12700H
  Memory: 3.22 GB / 15.63 GB
Binaries:
  Node: 18.16.0 - C:\Program Files\nodejs\node.EXE
  npm: 9.5.1 - C:\Program Files\nodejs\npm.CMD
  pnpm: 8.15.6 - ~\AppData\Local\pnpm\pnpm.EXE
Browsers:
  Edge: Chromium (123.0.2420.81)
  Internet Explorer: 11.0.22621.1
npmPackages:
  @vitejs/plugin-vue: ^5.0.4 => 5.0.4
  @vitejs/plugin-vue-jsx: ^3.1.0 => 3.1.0
  @vitest/coverage-v8: ^1.4.0 => 1.4.0
  vite: ^5.2.8 => 5.2.8
  vitest: ^1.4.0 => 1.4.0

Used Package Manager

pnpm

Validations

@hi-ogawa hi-ogawa added 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

hi-ogawa commented Apr 14, 2024

Thanks for the reproduction. It looks like it got broken when we added custom equality tester in v1.2.0 #4880.

The same issue can be also reproduced on Jest since the internal code is mostly same:
https://github.com/hi-ogawa/reproductions/tree/main/jest-circular-iterable

I attempted a fix #5535, but while doing that, I discovered a few cases only toMatchObject crashes but toEqual succeeds. https://stackblitz.com/edit/vitest-dev-vitest-tkc5b5?file=test%2Frepro.test.ts

Jest side seems to fixed this one already:

I'll try to address this toMatchObject specific issue separately.

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.

2 participants