mirror of
https://github.com/zebrajr/react.git
synced 2026-01-15 12:15:22 +00:00
Fail jest tests on any un-spied warnings
Originally #4223 -- we lost this when we switched to jest.
This commit is contained in:
35
scripts/jest/test-framework-setup.js
Normal file
35
scripts/jest/test-framework-setup.js
Normal file
@@ -0,0 +1,35 @@
|
||||
'use strict';
|
||||
|
||||
var env = jasmine.getEnv();
|
||||
|
||||
var oldError = console.error;
|
||||
var newError = function() {
|
||||
oldError.apply(this, arguments);
|
||||
var spec = env.currentSpec;
|
||||
if (spec) {
|
||||
var expectationResult = new jasmine.ExpectationResult({
|
||||
passed: false,
|
||||
message:
|
||||
'Expected test not to warn. If the warning is expected, mock it ' +
|
||||
'out using spyOn(console, \'error\'); and test that the warning ' +
|
||||
'occurs.',
|
||||
});
|
||||
spec.addMatcherResult(expectationResult);
|
||||
}
|
||||
};
|
||||
console.error = newError;
|
||||
|
||||
// Make sure console.error is set back at the end of each test, or else the
|
||||
// above logic won't work
|
||||
afterEach(function() {
|
||||
// TODO: Catch test cases that call spyOn() but don't inspect the mock
|
||||
// properly.
|
||||
|
||||
if (console.error !== newError && !console.error.isSpy) {
|
||||
var expectationResult = new jasmine.ExpectationResult({
|
||||
passed: false,
|
||||
message: 'Test did not tear down console.error mock properly.',
|
||||
});
|
||||
env.currentSpec.addMatcherResult(expectationResult);
|
||||
}
|
||||
});
|
||||
Reference in New Issue
Block a user