Jest: Feature request: fail on React proptype validation fail and other console errors

Created on 14 Nov 2016  路  14Comments  路  Source: facebook/jest

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.)

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 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?

All 14 comments

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

Was this page helpful?
0 / 5 - 0 ratings

Related issues

samzhang111 picture samzhang111  路  3Comments

kentor picture kentor  路  3Comments

Secretmapper picture Secretmapper  路  3Comments

hramos picture hramos  路  3Comments

ticky picture ticky  路  3Comments