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:
Pascal Hartig
2019-02-06 08:49:00 -08:00
committed by Facebook Github Bot
parent 765874f4be
commit 719dd65340
2 changed files with 18 additions and 1 deletions

14
static/globalTestSetup.js Normal file
View 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);
};