mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
RN: Eliminate Jest Log Spew
Summary: Eliminates all of the console logs that appear when successfully running Jest tests for React Native. Changelog: [Internal] Reviewed By: lunaleaps Differential Revision: D32304619 fbshipit-source-id: 8bc8ef9337ae6af588238cec7cfb874ac6067340
This commit is contained in:
committed by
Facebook GitHub Bot
parent
148c98ec80
commit
36bbd8fa31
@@ -102,15 +102,10 @@ describe('TextInput tests', () => {
|
||||
TextInput.State.focusTextInput(textInputRef.current);
|
||||
expect(textInputRef.current.isFocused()).toBe(true);
|
||||
expect(TextInput.State.currentlyFocusedInput()).toBe(textInputRef.current);
|
||||
// This function is currently deprecated and will be removed in the future
|
||||
expect(TextInput.State.currentlyFocusedField()).toBe(
|
||||
ReactNative.findNodeHandle(textInputRef.current),
|
||||
);
|
||||
|
||||
TextInput.State.blurTextInput(textInputRef.current);
|
||||
expect(textInputRef.current.isFocused()).toBe(false);
|
||||
expect(TextInput.State.currentlyFocusedInput()).toBe(null);
|
||||
// This function is currently deprecated and will be removed in the future
|
||||
expect(TextInput.State.currentlyFocusedField()).toBe(null);
|
||||
});
|
||||
|
||||
it('should unfocus when other TextInput is focused', () => {
|
||||
@@ -144,24 +139,17 @@ describe('TextInput tests', () => {
|
||||
expect(textInputRe1.current.isFocused()).toBe(false);
|
||||
expect(textInputRe2.current.isFocused()).toBe(false);
|
||||
|
||||
const inputTag1 = ReactNative.findNodeHandle(textInputRe1.current);
|
||||
const inputTag2 = ReactNative.findNodeHandle(textInputRe2.current);
|
||||
|
||||
TextInput.State.focusTextInput(textInputRe1.current);
|
||||
|
||||
expect(textInputRe1.current.isFocused()).toBe(true);
|
||||
expect(textInputRe2.current.isFocused()).toBe(false);
|
||||
expect(TextInput.State.currentlyFocusedInput()).toBe(textInputRe1.current);
|
||||
// This function is currently deprecated and will be removed in the future
|
||||
expect(TextInput.State.currentlyFocusedField()).toBe(inputTag1);
|
||||
|
||||
TextInput.State.focusTextInput(textInputRe2.current);
|
||||
|
||||
expect(textInputRe1.current.isFocused()).toBe(false);
|
||||
expect(textInputRe2.current.isFocused()).toBe(true);
|
||||
expect(TextInput.State.currentlyFocusedInput()).toBe(textInputRe2.current);
|
||||
// This function is currently deprecated and will be removed in the future
|
||||
expect(TextInput.State.currentlyFocusedField()).toBe(inputTag2);
|
||||
});
|
||||
|
||||
it('should render as expected', () => {
|
||||
|
||||
@@ -28,7 +28,7 @@ const JSTimers = require('../JSTimers');
|
||||
|
||||
describe('JSTimers', function () {
|
||||
beforeEach(function () {
|
||||
jest.spyOn(console, 'warn');
|
||||
jest.spyOn(console, 'warn').mockReturnValue(undefined);
|
||||
global.setTimeout = JSTimers.setTimeout;
|
||||
});
|
||||
|
||||
|
||||
@@ -17,7 +17,7 @@ describe('AssetUtils', () => {
|
||||
});
|
||||
|
||||
it('should return empty string and warn once if no cacheBreaker set (DEV)', () => {
|
||||
const mockWarn = jest.spyOn(console, 'warn');
|
||||
const mockWarn = jest.spyOn(console, 'warn').mockReturnValue(undefined);
|
||||
global.__DEV__ = true;
|
||||
expect(getUrlCacheBreaker()).toEqual('');
|
||||
expect(getUrlCacheBreaker()).toEqual('');
|
||||
|
||||
@@ -362,7 +362,7 @@ describe('VirtualizedList', () => {
|
||||
const layout = {width: 300, height: 600};
|
||||
let data = Array(20)
|
||||
.fill()
|
||||
.map((_, key) => ({key: String(key)}));
|
||||
.map((_, index) => ({key: `key-${index}`}));
|
||||
const onEndReached = jest.fn();
|
||||
const props = {
|
||||
data,
|
||||
|
||||
@@ -30,20 +30,20 @@ function mockFilterResult(returnValues) {
|
||||
}
|
||||
|
||||
describe('LogBox', () => {
|
||||
const {error, warn} = console;
|
||||
let consoleError;
|
||||
let consoleWarn;
|
||||
const {error, log, warn} = console;
|
||||
|
||||
beforeEach(() => {
|
||||
jest.resetModules();
|
||||
console.error = consoleError = jest.fn();
|
||||
console.warn = consoleWarn = jest.fn();
|
||||
console.error = jest.fn();
|
||||
console.log = jest.fn();
|
||||
console.warn = jest.fn();
|
||||
console.disableYellowBox = false;
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
LogBox.uninstall();
|
||||
console.error = error;
|
||||
console.log = log;
|
||||
console.warn = warn;
|
||||
});
|
||||
|
||||
@@ -329,6 +329,8 @@ describe('LogBox', () => {
|
||||
});
|
||||
|
||||
it('preserves decorations of console.error after installing/uninstalling', () => {
|
||||
const consoleError = console.error;
|
||||
|
||||
LogBox.install();
|
||||
|
||||
const originalConsoleError = console.error;
|
||||
@@ -356,6 +358,8 @@ describe('LogBox', () => {
|
||||
});
|
||||
|
||||
it('preserves decorations of console.warn after installing/uninstalling', () => {
|
||||
const consoleWarn = console.warn;
|
||||
|
||||
LogBox.install();
|
||||
|
||||
const originalConsoleWarn = console.warn;
|
||||
|
||||
@@ -11,8 +11,12 @@
|
||||
|
||||
const React = require('react');
|
||||
|
||||
let nativeTag = 1;
|
||||
|
||||
module.exports = viewName => {
|
||||
const Component = class extends React.Component {
|
||||
_nativeTag = nativeTag++;
|
||||
|
||||
render() {
|
||||
return React.createElement(viewName, this.props, this.props.children);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user