-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
fix(expect): fix toEqual
and toMatchObject
with circular references
#5535
fix(expect): fix toEqual
and toMatchObject
with circular references
#5535
Conversation
✅ Deploy Preview for fastidious-cascaron-4ded94 canceled.
|
@@ -334,7 +334,7 @@ export function iterableEquality(a: any, b: any, customTesters: Array<Tester> = | |||
return iterableEquality( | |||
a, | |||
b, | |||
[...filteredCustomTesters], | |||
[...customTesters], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure if this fix is entirely fool-proof for more complicated case, but at least this recursion with filteredCustomTesters
seems redundant.
Previously iterableEqualityWithStack
was calling iterableEquality(..., [... iterableEqualityWithStack], ...)
, but iterableEquality
is already setting up filteredCustomTesters
.
(I don't know how to explain this better...)
* wip * fix: array reference in subset
toEqual
and toMatchObject
with circular references
if ((pass && isNot) || (!pass && !isNot)) { | ||
const msg = utils.getMessage( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I haven't follow up this properly, but in some cases, utils.getMessage
also gets in loop (stacktrace shows loupe
is doing something).
For now, I hid it inside failure case since msg
is not used fro success case anyways.
@@ -452,7 +452,7 @@ export function subsetEquality(object: unknown, subset: unknown, customTesters: | |||
return undefined | |||
|
|||
return Object.keys(subset).every((key) => { | |||
if (isObjectWithKeys(subset[key])) { | |||
if (typeof subset[key] === 'object') { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not entirely convinced with the fix for subsetEquality
as well, but the "array" specific infinite recursion is due to seenReference
is missing array.
(Actually I'm fine with the fix, but I feel the implementation of subsetEquality
feels a little off in general since it doesn't take the approach of aStack/bStack
like eq
and iterableEquality
do)
Description
RangeError: Maximum call stack size exceeded
whentoMatchObject
with array circular references #5538This seems to be a regression from custom equality tester #4880 (introduced in v1.2.0). I haven't properly analyzed code, but this
filteredCustomTesters
looks fishy.Btw, it turned out it reproduces on Jest too since code looks mostly same https://github.com/hi-ogawa/reproductions/tree/main/jest-circular-iterable
Searching Jest issues, I found a similar issue and this reproduces on Vitest jestjs/jest#14734. They seemed to fixed this one already, so I'll try port back to Vitest later.(EDIT: this one is also partially fixed)
Please don't delete this checklist! Before submitting the PR, please make sure you do the following:
pnpm-lock.yaml
unless you introduce a new test example.Tests
pnpm test:ci
.Documentation
pnpm run docs
command.Changesets
feat:
,fix:
,perf:
,docs:
, orchore:
.