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
callToJSONoption 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-formatdependency, which will by default call atoJSONmethod 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-formatwill be validated and it will calltoJSONon symfony DOM items, which will trigger a backend request for atoJSONaction, which does not exist, thus breaking all tests.How:
Luckily
pretty-formathas a option which can be used to disable the wholetoJSONlogic.The testing library use only uses
pretty-formatto 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: