Disable callToJSON option used by pretty-format #1315
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
What:
This PR disable the
callToJSON
option used by the pretty-format dependency.Why:
These changes are needed to fix a conflict that happens when trying to add E2E tests to a project that uses Symfony's live components.
The issue is caused by the process of building the "pretty printed" DOM debug data.
This process is handled by the
pretty-format
dependency, which will by default call atoJSON
method on any object that defines it.See the relevant from
pretty-format
:This seems harmless most of the time but conflict with symfony's live component because the component DOM node is a proxied object which support any method being called on it (which will be interpreted as an "action").
For more context, here is the relevant code used by the proxy:
With this in mind, the
typeof val.toJSON === 'function'
check ofpretty-format
will be validated and it will calltoJSON
on symfony DOM items, which will trigger a backend request for atoJSON
action, which does not exist, thus breaking all tests.How:
Luckily
pretty-format
has a option which can be used to disable the wholetoJSON
logic.The testing library use only uses
pretty-format
to display DOM items which will never support this special method unless they are weirdly proxied.Disabling the option should thus be fairly safe and have no negative impact (the test suite seems to confirm it as all tests passes without issues).
Checklist: