Warn when console.error is used in tests
Summary: It's a bit hacky but apparently the recommended solution: https://stackoverflow.com/questions/28615293/is-there-a-jest-config-that-will-fail-tests-on-console-warn This will bail when a call to `console.error` is used in a test. If you *need to* use console.error in a test, then mock it. This will likely not pass yet, but let's fix all failures and then land it. Reviewed By: danielbuechele Differential Revision: D13898383 fbshipit-source-id: 0ca222a07433a9a311dc6bdf0d264342a59208be
This commit is contained in:
committed by
Facebook Github Bot
parent
765874f4be
commit
719dd65340
@@ -31,7 +31,10 @@
|
|||||||
"jest": {
|
"jest": {
|
||||||
"transform": {
|
"transform": {
|
||||||
"\\.(js)$": "<rootDir>/static/transforms/index.js"
|
"\\.(js)$": "<rootDir>/static/transforms/index.js"
|
||||||
}
|
},
|
||||||
|
"setupFiles": [
|
||||||
|
"<rootDir>/static/globalTestSetup.js"
|
||||||
|
]
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@jest-runner/electron": "^0.1.0",
|
"@jest-runner/electron": "^0.1.0",
|
||||||
|
|||||||
14
static/globalTestSetup.js
Normal file
14
static/globalTestSetup.js
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
/**
|
||||||
|
* Copyright 2018-present Facebook.
|
||||||
|
* This source code is licensed under the MIT license found in the
|
||||||
|
* LICENSE file in the root directory of this source tree.
|
||||||
|
* @format
|
||||||
|
*/
|
||||||
|
const defaultConsoleError = console.error;
|
||||||
|
|
||||||
|
console.error = function(message) {
|
||||||
|
defaultConsoleError(
|
||||||
|
'console.error used in a test. This will be an error in the near future.',
|
||||||
|
);
|
||||||
|
defaultConsoleError.apply(console, arguments);
|
||||||
|
};
|
||||||
Reference in New Issue
Block a user