add option to fail tests that print errors and warnings
See original GitHub issueDo you want to request a feature or report a bug?
Feature.
What is the current behavior?
Tests pass even if they print errors and warnings to the console.
What is the expected behavior?
It would be nice if we could force the test to fail.
Our test suite prints lots of things like this:
console.warn node_modules/moment/moment.js:293
Deprecation warning: value provided is not in a recognized RFC2822 or ISO format. moment construction falls back to js Date(), which is not reliable across all browsers and versions. Non RFC2822/ISO date formats are discouraged and will be removed in an upcoming major release. Please refer to http://momentjs.com/guides/#/warnings/js-date/ for more info.
console.error node_modules/fbjs/lib/warning.js:33
Warning: Each child in an array or iterator should have a unique "key" prop.
(node:15601) UnhandledPromiseRejectionWarning: SyntaxError: The string did not match the expected pattern.
console.error node_modules/fbjs/lib/warning.js:33
Warning: `value` prop on `input` should not be null. Consider using an empty string to clear the component or `undefined` for uncontrolled components.
These are all legitimate errors that we should fix, yet our automated tests pass. If Jest could be made to fail, that would encourage developers to keep the tests clean.
Issue Analytics
- State:
- Created 5 years ago
- Reactions:7
- Comments:24 (6 by maintainers)
Top Results From Across the Web
Is there a jest config that will fail tests on console.warn?
Now, jest will fail when messages are passed to console.warn or console.error . create-react-app Docs - Initializing Test Environment.
Read more >Warnings as errors and tests - Dashbit Blog
Let's discuss the --warnings-as-errors option, how we can use it during compilation and tests, and finally our recommendations for using it ...
Read more >Catch warnings in Jest tests | Ben Ilegbodu
How to configure Jest to fail tests on console warnings and errors.
Read more >C# Compiler Options - errors and warnings - Microsoft Learn
C# Compiler Options to report errors and warnings · To get information about an error or warning, you can look up the error...
Read more >How to test a function that's expected to throw error in jest…
This caused the error I was getting. Here are the correct ways to write the unit tests: Based on the warning on the...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Here’s the variant I landed on, using Node’s
Util.format
function to preserve console string formatting via arguments in the error output:cc @akx, re:
This can already be achieved with a couple lines of code.