Files
react-native/packages/react-native/jest/local-setup.js
T
Moti ZilbermanandFacebook GitHub Bot 7f82e16c7d Reenable console.log in tests (#41330)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/41330

D41564032 made `console.log` (as well as `debug` and `info`) a noop in tests within the React Native repo. Here we allow them through while still throwing errors on `console.error` and `console.warn`.

Changelog: [Internal]

Reviewed By: NickGerleman

Differential Revision: D51002264

fbshipit-source-id: 44ca8bef38695dd76fe509341adced887bef2e6b
2023-11-07 11:16:02 -08:00

29 lines
687 B
JavaScript

/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @format
*/
// Global setup for tests local to the react-native repo. This setup is not
// included in the react-native Jest preset.
'use strict';
require('./setup');
const consoleError = console.error;
const consoleWarn = console.warn;
console.error = (...args) => {
consoleError(...args);
throw new Error('console.error() was called (see error above)');
};
console.warn = (...args) => {
consoleWarn(...args);
throw new Error('console.warn() was called (see warning above)');
};