-
Notifications
You must be signed in to change notification settings - Fork 24.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fail tests on
console.error()
or console.warn()
Summary: This makes it so that React Native unit tests will fail if code unexpectedly outputs a warning or error (which would show as a redbox error). This logic split out from the normal `jest/setup.js` which is included by the jest-preset, to only effect our tests instead of existing RN Jest users. Changelog: [Internal][Changed] - Fail tests on `console.error()` or `console.warn()` Reviewed By: huntie Differential Revision: D41564032 fbshipit-source-id: 3cc7d3a8433fcb75f654669b9c350dea2da937a8
- Loading branch information
1 parent
da4243b
commit 217696e
Showing
4 changed files
with
45 additions
and
3 deletions.
There are no files selected for viewing
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/** | ||
* 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'; | ||
|
||
const consoleError = console.error; | ||
const consoleWarn = console.warn; | ||
|
||
jest.spyOn(console, 'debug').mockImplementation(() => { | ||
// Blackhole console output | ||
}); | ||
|
||
jest.spyOn(console, 'info').mockImplementation(() => { | ||
// Blackhole console output | ||
}); | ||
|
||
jest.spyOn(console, 'log').mockImplementation(() => { | ||
// Blackhole console output | ||
}); | ||
|
||
jest.spyOn(console, 'error').mockImplementation((...args) => { | ||
consoleError(...args); | ||
throw new Error('console.error() was called'); | ||
}); | ||
|
||
jest.spyOn(console, 'warn').mockImplementation((...args) => { | ||
consoleWarn(...args); | ||
throw new Error('console.warn() was called'); | ||
}); | ||
|
||
require('./setup'); |