gcedo gcedo - 1 year ago 125
React JSX Question

Karma and React, have warnings to cause errors

I am using Karma with mocha to test my React components. I have some warnings displayed when the PropTypes are not matched. However it would be really interesting to have these warnings to cause an actual error, as to track down the test and fix it.

Do you know how this could be achieved?

Answer Source

You can replace the console.warn method with your own and throw when the message provided matches a certain pattern.

let warn = console.warn;
console.warn = function(warning) {
  if (/(Invalid prop|Failed propType)/.test(warning)) {
    throw new Error(warning);
  warn.apply(console, arguments);
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download