It would be great if we could have tests fail when they produce a console error, instead of just outputting it. I've seen components getting updated, but not their tests. This goes unnoticed because it doesn't cause a failure.
(Nb: We also have code that is supposed to produce a console.warn, which shouldn't cause a test fail.)
In your test or setup file you can do something like this:
console.error = message => {
throw new Error(message);
}
Unfortunately we cannot just overwrite the console in Jest for everybody so this should be opt-in on a per-project basis. If you'd like to work on a PR that adds something like jest.throwOnConsoleError() (I'm sure there is a better name for this), I'm happy to work with you on that.
Thanks for your reply! I will try to get a PR in next week.
Closing, as this should be further handled in a related PR.
@cpojer @thymikee @hkrutzer It doesn't look like there was a PR created for this, correct? Is this still something you think we should add?
@MattCopenhaver you're right, there was no PR on this topic
Feel free to send us one! :)
Planning on it - but since this will be my first time contributing here, it might take some time.
Feel free to join us on discord if you'd like to discuss anything! http://facebook.github.io/jest/support.html
any movement on this? I might try to work on this if not.
@uxtx Please do! Sorry I have not had time to make any meaningful progress.
No problem! I've got some time this weekend. I'm thinking this should be a config option you could set in package json... maybe something like throwOnConsole that would accept either an array of console types to error on or Boolean to throw on all/none console errors... defaulted to false. Thoughts?
My thoughts exactly.
Sooo, was this never done? I want it, too.
For anyone else landing here looking for this feature, you can enable this functionality with Jest setupFiles configuration with: jest-prop-type-error
Most helpful comment
No problem! I've got some time this weekend. I'm thinking this should be a config option you could set in package json... maybe something like
throwOnConsolethat would accept either an array of console types to error on or Boolean to throw on all/none console errors... defaulted to false. Thoughts?