You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[Bug]: Since Jest 29.1.0 comparing an array of complex class instances throws an error "TypeError: this is not a typed array" #14375
changed the title [-][Bug]: Since Jest 29.1.0 comparing an array of complex classes throws an error "TypeError: this is not a typed array"[/-][+][Bug]: Since Jest 29.1.0 comparing an array of complex class instances throws an error "TypeError: this is not a typed array"[/+]on Jul 29, 2023
Thanks for your response. The oddness occurs with any class from the library, I did the example with the rectangle just to make it short but it breaks in any place that I use toMatchObject with childrenproperty (almost all the classes inherith from the same base class). That has not been occurring until version 29.1.0 and the library has been working with that matcher since a long time ago (jest 28.x.x).
Something curious is that it doesn‘t fail with toEqual or toStrictEqual, it is just with toMatchObject, and all of them check that property.
What you are getting with the console.log is the same that you get if you do this inside a test:
If I got it right, the changes I am pointing to are related (or mostly related) with the toMatchObject() matcher. That explains why all works well with other matchers.
Could you confirm if adding the following to the package.json allows to to upgrade Jest:
The object returned by JSDOM's createElementNS() method has _globalObject.window object. This object has more stuff installed by JSDOM and those have _globalObject.window prop. So here is what I tried:
Hi @mrazauskas,
Yes, with @jest/expect-utils29.3.1 the issue doesn‘t occur and I can even upgrade to jest29.6.2 without any issues.
That is aligned with my debugging yesterday, I placed breakpoints and I noticed that the issue seems to be inside @jest/expect-utils/build/jasmineUtils.js.
Regards
The object returned by JSDOM's createElementNS() method has _globalObject.window object. This object has more stuff installed by JSDOM and those have _globalObject.window prop. So here is what I tried:
It could be related to that indeed, as jest-dom mimics the real DOM native APIs, window has a property named globalThis which is a reference to itself, maybe this is the root of the maximum call stack.
If I got it right, jsdom is using Symbols for information hiding. After #13639 that concept got broken, because toMatchObject() now looks at props with Symbol keys. Can be that circular references are not handled well. For instance, globalThis/window could be the place which ends up in infinite loop.
@lpizzinidev@joshkel Would you have a moment to take a look? It seems that support of Symbol property keys broke Jest for users of jsdom.
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.
Activity
[-][Bug]: Since Jest 29.1.0 comparing an array of complex classes throws an error "TypeError: this is not a typed array"[/-][+][Bug]: Since Jest 29.1.0 comparing an array of complex class instances throws an error "TypeError: this is not a typed array"[/+]mrazauskas commentedon Jul 29, 2023
There is something odd inside the
rectangle.elementprop, because the following is passing:If I do
console.log(rectangle.element)all it shows is:SVGElement {}. Hard to say what is going on there.elchininet commentedon Jul 29, 2023
Hi @mrazauskas,
Thanks for your response. The oddness occurs with any class from the library, I did the example with the rectangle just to make it short but it breaks in any place that I use
toMatchObjectwithchildrenproperty (almost all the classes inherith from the same base class). That has not been occurring until version29.1.0and the library has been working with that matcher since a long time ago (jest 28.x.x).Something curious is that it doesn‘t fail with
toEqualortoStrictEqual, it is just withtoMatchObject, and all of them check that property.What you are getting with the
console.logis the same that you get if you do this inside a test:Element will be always an
SVGElement.Regards
elchininet commentedon Jul 29, 2023
As you discovered that the issue is with the
elementproperty, I did a small test and this also fails:It doesn‘t fail with
toBe,toEqualortoStrictEqual(and it doesn‘t fail either withjest 29.0.3).mrazauskas commentedon Jul 30, 2023
Thanks for the idea. I was able to recreate the issue in an empty repro only with
jestandjest-environment-jsdominstalled:I was using Yarns
resolutionsand the problem narrowed down to@jest/expect-utilspackage:"@jest/expect-utils": "29.3.1"the test is passing;"@jest/expect-utils": "29.4.0"gives: "serializes to the same string" (possibly fix:expect.toMatchObjectignores symbol key properties #13639);"@jest/expect-utils": "29.4.1"gives: "Maximum call stack size exceeded" (possibly Include symbol keys when diffing objects #13810);"@jest/expect-utils": "29.4.1"has no changes so it trows the same error;"@jest/expect-utils": "29.4.3"trips up Jest event more, it hangs up just like you described (possibly fix: added inherited string keys check onsubsetEqualitymethod #13824).If I got it right, the changes I am pointing to are related (or mostly related) with the
toMatchObject()matcher. That explains why all works well with other matchers.Could you confirm if adding the following to the
package.jsonallows to to upgrade Jest:mrazauskas commentedon Jul 30, 2023
The object returned by JSDOM's
createElementNS()method has_globalObject.windowobject. This object has more stuff installed by JSDOM and those have_globalObject.windowprop. So here is what I tried:It passes with
"@jest/expect-utils": "29.3.1", but freezes Jest with"@jest/expect-utils": "29.4.0".elchininet commentedon Jul 30, 2023
Hi @mrazauskas,
Yes, with
@jest/expect-utils29.3.1the issue doesn‘t occur and I can even upgrade tojest29.6.2without any issues.That is aligned with my debugging yesterday, I placed breakpoints and I noticed that the issue seems to be inside
@jest/expect-utils/build/jasmineUtils.js.Regards
elchininet commentedon Jul 30, 2023
@mrazauskas,
I didn‘t see this comment before.
It could be related to that indeed, as
jest-dommimics the real DOM native APIs,windowhas a property namedglobalThiswhich is a reference to itself, maybe this is the root of the maximum call stack.mrazauskas commentedon Jul 30, 2023
If I got it right,
jsdomis using Symbols for information hiding. After #13639 that concept got broken, becausetoMatchObject()now looks at props with Symbol keys. Can be that circular references are not handled well. For instance,globalThis/windowcould be the place which ends up in infinite loop.@lpizzinidev @joshkel Would you have a moment to take a look? It seems that support of Symbol property keys broke Jest for users of
jsdom.mhughes2012 commentedon Feb 2, 2026
I'll work on this.
SimenB commentedon May 7, 2026
https://github.com/jestjs/jest/releases/tag/v30.4.0
github-actions commentedon Jun 22, 2026
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.