Disable callToJSON option used by pretty-format#1315
Disable callToJSON option used by pretty-format#1315AdrienClairembault wants to merge 1 commit intotesting-library:mainfrom
Conversation
|
This pull request is automatically built and testable in CodeSandbox. To see build info of the built libraries, click here or the icon next to each commit SHA. Latest deployment of this branch, based on commit 59b21a5:
|
|
Thanks @AdrienClairembault. Can you please open an issue with a reproduction of the problem so we'll understand what we're trying to fix here with a real life example? Also, I'm not entirely sure we'd want to merge this change as this looks like the default behavior that fits most use cases. |
|
I have opened an issue which hopefully should be a bit clearer.
I completely understand this and very much respect that you would not blindly change a configuration option and risk potential side effects. My point of view is that the change would be safe as the option is not relevant when doing DOM nodes comparison but javascript is not my main field at all and I would appreciate if someone with more experience on the subject could confirm it. |
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: