Open AdrienClairembault opened 5 months ago
Uh oh! @AdrienClairembault, the image you shared is missing helpful alt text. Check your issue body.
Alt text is an invisible description that helps screen readers describe images to blind or low-vision users. If you are using markdown to display images, add your alt text inside the brackets of the markdown image.
Learn more about alt text at Basic writing and formatting syntax: images on GitHub Docs.
I think it makes more sense to let users configure the pretty-format options globally. We're going over these again and again and I think there's no good one-size-fits-all. I'd definitely prefer if we call toJson
by default since it's not expected that this triggers side-effects. But if a library wants to do that, I'd rather have users explicitly opt-out of it
I think it makes more sense to let users configure the pretty-format options globally. We're going over these again and again and I think there's no good one-size-fits-all. I'd definitely prefer if we call
toJson
by default since it's not expected that this triggers side-effects. But if a library wants to do that, I'd rather have users explicitly opt-out of it
This was the approach I was leaning towards too. We can pass option
to pretty-print
instead of going with a "this" or "that" approach.
Any news on this? Just stumbled across this issue myself.
@testing-library/dom
version: 10.1.0Cypress
13.10.0 +@testing-library/cypress
10.0.2Symfony
7.1.0 (full stack PHP framework)Relevant code or config:
A very simple test case like the one below will break due to some conflicts with the way symfony live components operate.
When the testing library attempt to compute the DOM (to display it as debug information), it accidentally trigger mutliple invalid backend requests towards the symfony server:
Problem description:
The problem is caused by a feature of a peer dependency:
pretty-format
. This dependency is able to recursively pretty print both DOM nodes and complex javacript variables.To support complex javascript variable, pretty-print has a specific
callToJSON
feature that will try to call atoJSON
method if it exists on ALL items it is recursively iterating on. I suppose this is mainly useful to support the native implementationDate.prototype.toJSON
and allow users to add this method on their objects if need be.This feature is what leads to the issue, following this code path:
@testing-library/dom
try to pretty print the DOM container and its children using itsprettyDOM()
method.prettyDOM()
method then make use of thepretty-format
dependency, specifically theformat()
method.format()
method iterate on the container and its children, using itsprintComplexValue()
method.printObjectProperties()
method, with the goal of visiting these properties as potential children.format()
/printObjectProperties()
process repeat until we end up iterating over the DOM node of a symfony component, which is where our trouble really begins.printObjectProperties()
method is able to find a specific__component
property on our symfony component.__component
property is a Proxy instance that accept any method call (I am not familiar why this specific design is in place, but the calling method name is the action that the component will try to apply to the page).printComplexValue()
method assume that this Proxy support thetoJSON
method and happily call it.toJSON
action.Suggested solution:
The solution proposed in #1315 is to disable the
callToJSON
feature of thepretty-format
dependency using its configuration options.I am not very familiar with the
pretty-format
library but it seems very powerful and a lot of its feature are meant to handle complex javascript structures.Thus,
callToJSON
is one of these advanced features that seems useless to me if you are only doing DOM pretty printing, which I belive is how it is used by@testing-library/dom
(correct me if I'm wrong).With this in mind, disabling this feature would fix the conflicts with symfony forms without breaking anything as it is (hopefully) irrelevant for DOM printing.
I suppose it could also lead to very small performances improvement as disabling this feature remove a few checks for each DOM node that we iterate over (maybe it could be impactful on huge DOMs ?).