-
-
Notifications
You must be signed in to change notification settings - Fork 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
Mount not working (RangeError: Invalid string length) #1050
Comments
Ok, my bad. What is really not working in the example is mounting a component with Enzyme and trying to test it with the Jest's Snapshot Testing right away. Components must be converted to Json for them to be stored and compared as snapshots. Best way to do it would be using enzyme-to-json to transform mounted components to JSON: import toJson from 'enzyme-to-json'
...
expect(toJson(wrapper)).toMatchSnapshot() If you don't want to write import serializer from 'enzyme-to-json/serializer';
expect.addSnapshotSerializer(serializer)
...
expect(wrapper).toMatchSnapshot() You can also keep using Jest's own renderer, but you'll be missing all the Enzyme's features related to the component management. Closing this, thanks! |
Is anyone still seeing this issue even after leveraging enzyme-to-json? |
@tsneed290 Not me, it works perfectly. Make sure you are using one of the serializations after importing the library, either using the |
I am still having it. I can see the wrapper in console with debug() getting mounted perfectly but when I use toMatchSnapshot(), it fails with invalid string length error. I tried using enzyme-to-json but still it gives the same error. render() works fine but as I want to use find() and simulate(), mount() is the only option. |
I am also seeing this:
versions:
|
@schtauffen what is "pretty-format"? It seems like it's not an enzyme bug. |
@ljharb it is a jest dependency. I've just written tests that don't use toMatchSnapshot in the cases it was failing, for now. I will try to contribute more information in the applicable repo if I find anything which leans one way or the other. |
enzyme has no snapshot support; you probably should file this on enzyme-to-json. |
I am also having this issue... |
Adding the below code to my
|
Thanks @likethemammal that solved the issue for me too! |
I was having the same issue even with |
**What does this PR do?** A clear and concise description with your runway ticket url. Runway https://nitro.powerhrg.com/runway/backlog_items/PLAY-1351 Upgrades highcharts from version 9 to 10 I added the boiler plate for tests for the graphs because they had nothing. I would have liked to add snapshot testing but was having issues because highcharts generates random ids for different parts of the graphs your suppose to be able to do things like expect.any(String) https://jestjs.io/docs/snapshot-testing#property-matchers But you need to download other library(s) to get it to work. I bailed because its out of scope other people have this issue enzymejs/enzyme#1050 ``` test('bargraph has right html structure', () => { const { container } = render( <BarGraph data={{ testid: testId }} /> ); expect(container).toMatchSnapshot({ id: expect.any(String) }); }); ``` ![Screenshot 2024-05-24 at 9 43 20 AM](https://github.com/powerhome/playbook/assets/38965626/cd3c7730-3f9a-4e2e-9b26-b0c8709d0b3c) **How to test?** Steps to confirm the desired behavior: Everything should be the same, just a version bump
Hi everyone,
maybe I am missing something essential, but I am trying to use
mount
for some testing and it is just not working. These are my Jest and Enzyme versions:I have tried in different types of components and even in the simplest one I came up to, it still not works. This is the component code:
And this is the test I wrote for it:
And the output I get is this:
I googled this error and the only thing I found is that it might be some out of memory problem, and that is why I tried it with a really simple component, but still it doesn't work. I have tested this in Ubuntu and Mac OS X, both with the same results.
Thanks in advance for those who can help me with it!
The text was updated successfully, but these errors were encountered: