Description
The pretty-dom + getElementError
error that Testing Library outputs is super long for the e2e use case since we're working with entire pages instead of small units. So far, we're thinking of addressing this with either or both of the following:
- Modify the default
getElementError
to better suit our use case (strip<style />
+<script />
? — see last comment below for details/ideas) - Support the
getElementError
configuration option from Testing Library
Original Discussion
- @sebinsua — Expect assertions can't be used due to returning ElementHandles instead of Locators #430 (comment)
One other thing -- is there any way that we could allow users to configure getElementError? I'm finding the length of the error messages incredibly long as it prints out a bunch of HTML and CSS and I have to scroll up a long way to find the actual error message.
- @jrolfs — Expect assertions can't be used due to returning ElementHandles instead of Locators #430 (comment)
Okay, so this is something I've wanted to address since I created this library. I'd be curious if you have an idea of what a better default implementation/output would be. I do think we can add support for this option, but I really think we also need a better default because the e2e use case just always produces so much output. I also want to figure out how to preserve the ANSI formatting in the Testing Library errors.
- @sebinsua — Expect assertions can't be used due to returning ElementHandles instead of Locators #430 (comment)
I agree that we might want to change the default getElementError and have a few suggestions.
- It outputs huge amounts of inline CSS/HTML in our case. This seems to be because of pretty-dom which sets a length limit of 7000 by default (!!!). My recommendation would be to inline getElementError but without the postfixed prettifiedDOM (and with a comment linking back to their original implementation). Actually, for now I can set DEBUG_PRINT_LIMIT=0 to get the same behaviour...!
- I've also found the logic which prints out roles found on the screen is controlled by a hidden config._disableExpensiveErrorDiagnostics option (which they switch on/off during waitFor). I wonder if we could have this be switched on/off via an environment variable? I don't currently know whether it should default to true or false as although it buries the error message it's incredibly helpful!