Skip to content

Instantly share code, notes, and snippets.

@jsdf
Created November 5, 2015 09:27
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save jsdf/6fc35890e4ed4a219072 to your computer and use it in GitHub Desktop.
Save jsdf/6fc35890e4ed4a219072 to your computer and use it in GitHub Desktop.
Make React PropType warnings throw errors in Jasmine/Jest
var util = require('util');
// nobody cares about warnings so lets make them errors
// keep a reference to the original console methods
var consoleWarn = console.warn;
var consoleError = console.error;
function logToError() {
throw new Error(util.format.apply(this, arguments).replace(/^Error: (?:Warning: )?/, ''));
}
jasmine.getEnv().beforeEach(function() {
// make calls to console.warn and console.error throw an error
console.warn = logToError;
console.error = logToError;
});
jasmine.getEnv().afterEach(function() {
// return console.warn and console.error to default behaviour
console.warn = consoleWarn;
console.error = consoleError;
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment