Created
November 5, 2015 09:27
-
-
Save jsdf/6fc35890e4ed4a219072 to your computer and use it in GitHub Desktop.
Make React PropType warnings throw errors in Jasmine/Jest
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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