vtambourine vtambourine - 2 months ago 14
React JSX Question

How to catch React propTypes warnings on server?

While rendering React components on server all of the propTypes warning messages are falling to general output or

. For example, this is visible only in terminal or in general application log:

Warning: Failed propType: Required prop `title` was not specified in `Page`.

Is there any way to catch this warnings and transform them or pipe them into another direction? For instance, I want to separate application log and React (as template engine) log. How can I do it?


Like @m01, I wanted to make sure that any react errors (and in fact any js errors) cause my unit tests to fail, but I found a much simpler way to do it. At the top level of your tests, put this:

beforeAll(() => {
  console.error = (error) => {
    throw new Error(error);