-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Jest + TS + Vite = RangeError: Invalid string length #1230
Comments
I encountered the same RangeError when testing components that use ShadowDOM - seems like something is trying to serialize a circular structure that creates a massive string. Sometimes this causes tests to be very slow and others it only causes the prettyDOM call used for debugging failures to print an error instead of the DOM. |
Hi @kappys1, thanks for opening this one. |
|
RangeError: Invalid string length
|
can i get a fix for it? |
It happens because you have an error in your test and makes a loop that it's not possible show in a readable way... then to display the error better I added this plugin It could have a very expensive cost... so I recommend only activate this when you have this kind of error and want to fix it. How I implement it? file: import { screen } from 'shadow-dom-testing-library';
// jest env does not support CSSStyleSheet.replace method. Therefore before the test runs
// we need to polyfill the construct style sheet implementation.
// learn more: https://github.com/ionic-team/stencil/issues/2277
import 'construct-style-sheets-polyfill';
// Required to avoid the following Invalid string error
jest.mock('@testing-library/react', () => ({
...jest.requireActual('@testing-library/react'),
screen,
})); Include or remove this import to allow displaying the most readable error within your jest configuration file, in my case: import './shadow-dom'; I hope it helps a lot. |
@testing-library/react
version: 14.0.0Testing Framework and version:
Other relevant dependencies:
Relevant code or config:
Example test
jest.setup.ts
jest.config.ts
What you did:
Run my tests normally with the configuration above and it fails.
What happened:
when I run my tests, the error that appears is this one:
and if I remove the transform in my
.swcrc
file get this error:Also, I have tried different solutions found on the internet like add this in
jest.setup.ts
file:But I get the first error mentioned above.
Problem description:
As I mention Above it occurs when I tried to run a normal test with testing library, the other ones without React code works fine.
The text was updated successfully, but these errors were encountered: