-
Notifications
You must be signed in to change notification settings - Fork 232
Noisy React console error output is not automatically suppressed as documented when using test frameworks other than Jest #564
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Noisy React console error output is not automatically suppressed as documented when using test frameworks other than Jest #564
Comments
Hi @jaydenseric, Sorry this caused you some strife. So much focus was put into ensuring that the functionality was able to be disabled for those that didn't want it that I failed to consider all the various ways other people might want to use it. While it's true that we assume the majority of our users will be testing with I will say that the console logs are actually a side effect of using React and we have always (perhaps only internally) considered the suppression a curtesy to our users rather than a feature per se as the tests do pass with the logs present. That said, I think option 2 very achievable here and we should strive for that. I also don't see why doing option 1 and improving the documentation around this can't also be done as well as providing an exported utility. Are you interested in making a PR for this? |
Thanks for that, it's great to have a pure version available. Normally messing with a native global API like
If I end up using |
No worries. It's not a big change so I'm happy to take it on, but have some personal stuff on this weekend and most of next week so won't get to it until after that. If anyone else comes across this please consider it fair game and have a crack. Just leave a message here so we know you're looking at it. |
🎉 This issue has been resolved in version 5.1.0 🎉 The release is available on: Your semantic-release bot 📦🚀 |
react-hooks-testing-library
version: v5.0.3Reproduction:
In a blank project, run:
In
test.js
:Run:
Notice the unexpected console error output in the terminal:
Problem description:
The documentation says:
In truth, patching only occurs if certain
beforeEach
andafterEach
globals, arbitrary to specific testing frameworks, are present:react-hooks-testing-library/src/core/console.ts
Lines 6 to 7 in c6de60e
Presumably it's assumed that every project in the world uses Jest 🙃
In another part of the docs:
“this library should work without issues with any of the alternatives” is not accurate. Plenty of testing frameworks don't mess with globals at all, while some do, but not in the same way as Jest. I use
test-director
to test my published packages (55.9 kB install size vs 34.4 MB forjest
). Sometimes it makes sense to avoid a "framework" altogether and just use a vanilla Node.js script with the Node.jsassert
API.Suggested solutions:
Do nothing, except update all the documentation to explain specifically what globals need to present for the automatic console error suppression to work, and ideally list what testing frameworks do or don't provide these globals.
This is not great because it doesn't provide an elegant solution for users with a test environment that doesn't provide these globals; they would be forced to either accept the console noise or hackily define
beforeEach
andafterEach
globals in test scripts just forreact-hooks-testing-library
to use. It smells to have to copy the globals of an arbitrary testing framework not used in your codebase. The people that specifically chose a testing library that doesn't pollute the global namespace will be opposed to a globals based hack. From a code quality / maintenance perspective, it would not be intuitive without elaborate comments whatbeforeEach
andafterEach
refers to or why that workaround code is there.Support console error output suppression for any testing environment. Export functions to monkeypatch and restore the global
console
, available via the index and deep imports. Internally, these same functions could be used with the automaticbeforeEach
andafterEach
globals detection.The text was updated successfully, but these errors were encountered: