react-testing-library: Log from .logTestingPlaygroundURL is to big and not working
Hello everybody.
When using
screen.logTestingPlaygroundURL()
Sometimes the generated URL is to big and when you paste it in the browser. the playground just stays empty, I found it to be random aswell, sometimes the same component generates a really big URL, and other times a smaller one, wich works, but it’s kinda luck related on that one, sometimes i have to re-run my test for 5 to 10 times to get a URL that works.
I use this feature for making easier to find elements on the screen that will be used on my test, and the best queries to get to them, since the playground is great for that.
My component for the related test that this issue occurs is quite big, maybe thats the problem? Any idea on how to make it work on bigger components, or should i try a diferent aproach?
Thanks!
About this issue
- Original URL
- State: open
- Created 5 years ago
- Reactions: 1
- Comments: 18 (7 by maintainers)
I get this error all the time. To reproduce it you just need to render a component big enough. For some our tests we have to render a huge component which results in a lot of HTML. I guess the HTML is encoded in the URL somehow and that’s why the URL is too big.
Example:
Was anyone able to find a fix here? I am also getting the same error with rendering components that are too large
After investing a lot of hours and comparing strings, I finally found out. Its not related to React Testing Library, rather its related to Dom Testing Library. And its not the issue of encoded string, rather its the issue with printing the string on terminal. Somehow when we do
console.log, it skips some characters in the string and prints the wrong string. When that string is supplied todecompressFromEncodedURIComponentoflz-string, it returns null. Hence the playground does not show anything.What works:
screen.logTestingPlaygroundURL(). The watched value provides the correct string which can simply be pasted on browser and playground would show the rendered stuff.console.errorinstead ofconsole.loginscreen.tsin Dom Testing Library, or useconsole.errorwith the returned value ofscreen.logTestingPlaygroundURL(), i.econsole.error(screen.logTestingPlaygroundURL()). The only issue withconsole.erroris jest considers it as actual error and fails the test.screen.logTestingPlaygroundURL()onto some file.I would love to fix it in Dom Testing Library, but I am not able to find a way other than
console.error, but it would affect the DX, seeing test being failed without any reason.A repro was provided in https://github.com/testing-library/react-testing-library/issues/974#issuecomment-1821336353, @eps1lon or @MatanBobi could you reopen this issue please?