Skip to content

Commit 36bbd8f

Browse files
yungstersfacebook-github-bot
authored andcommitted
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
1 parent 148c98e commit 36bbd8f

File tree

6 files changed

+17
-21
lines changed

6 files changed

+17
-21
lines changed

Libraries/Components/TextInput/__tests__/TextInput-test.js

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -102,15 +102,10 @@ describe('TextInput tests', () => {
102102
TextInput.State.focusTextInput(textInputRef.current);
103103
expect(textInputRef.current.isFocused()).toBe(true);
104104
expect(TextInput.State.currentlyFocusedInput()).toBe(textInputRef.current);
105-
// This function is currently deprecated and will be removed in the future
106-
expect(TextInput.State.currentlyFocusedField()).toBe(
107-
ReactNative.findNodeHandle(textInputRef.current),
108-
);
105+
109106
TextInput.State.blurTextInput(textInputRef.current);
110107
expect(textInputRef.current.isFocused()).toBe(false);
111108
expect(TextInput.State.currentlyFocusedInput()).toBe(null);
112-
// This function is currently deprecated and will be removed in the future
113-
expect(TextInput.State.currentlyFocusedField()).toBe(null);
114109
});
115110

116111
it('should unfocus when other TextInput is focused', () => {
@@ -144,24 +139,17 @@ describe('TextInput tests', () => {
144139
expect(textInputRe1.current.isFocused()).toBe(false);
145140
expect(textInputRe2.current.isFocused()).toBe(false);
146141

147-
const inputTag1 = ReactNative.findNodeHandle(textInputRe1.current);
148-
const inputTag2 = ReactNative.findNodeHandle(textInputRe2.current);
149-
150142
TextInput.State.focusTextInput(textInputRe1.current);
151143

152144
expect(textInputRe1.current.isFocused()).toBe(true);
153145
expect(textInputRe2.current.isFocused()).toBe(false);
154146
expect(TextInput.State.currentlyFocusedInput()).toBe(textInputRe1.current);
155-
// This function is currently deprecated and will be removed in the future
156-
expect(TextInput.State.currentlyFocusedField()).toBe(inputTag1);
157147

158148
TextInput.State.focusTextInput(textInputRe2.current);
159149

160150
expect(textInputRe1.current.isFocused()).toBe(false);
161151
expect(textInputRe2.current.isFocused()).toBe(true);
162152
expect(TextInput.State.currentlyFocusedInput()).toBe(textInputRe2.current);
163-
// This function is currently deprecated and will be removed in the future
164-
expect(TextInput.State.currentlyFocusedField()).toBe(inputTag2);
165153
});
166154

167155
it('should render as expected', () => {

Libraries/Core/Timers/__tests__/JSTimers-test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ const JSTimers = require('../JSTimers');
2828

2929
describe('JSTimers', function () {
3030
beforeEach(function () {
31-
jest.spyOn(console, 'warn');
31+
jest.spyOn(console, 'warn').mockReturnValue(undefined);
3232
global.setTimeout = JSTimers.setTimeout;
3333
});
3434

Libraries/Image/__tests__/AssetUtils-test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ describe('AssetUtils', () => {
1717
});
1818

1919
it('should return empty string and warn once if no cacheBreaker set (DEV)', () => {
20-
const mockWarn = jest.spyOn(console, 'warn');
20+
const mockWarn = jest.spyOn(console, 'warn').mockReturnValue(undefined);
2121
global.__DEV__ = true;
2222
expect(getUrlCacheBreaker()).toEqual('');
2323
expect(getUrlCacheBreaker()).toEqual('');

Libraries/Lists/__tests__/VirtualizedList-test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -362,7 +362,7 @@ describe('VirtualizedList', () => {
362362
const layout = {width: 300, height: 600};
363363
let data = Array(20)
364364
.fill()
365-
.map((_, key) => ({key: String(key)}));
365+
.map((_, index) => ({key: `key-${index}`}));
366366
const onEndReached = jest.fn();
367367
const props = {
368368
data,

Libraries/LogBox/__tests__/LogBox-test.js

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,20 +30,20 @@ function mockFilterResult(returnValues) {
3030
}
3131

3232
describe('LogBox', () => {
33-
const {error, warn} = console;
34-
let consoleError;
35-
let consoleWarn;
33+
const {error, log, warn} = console;
3634

3735
beforeEach(() => {
3836
jest.resetModules();
39-
console.error = consoleError = jest.fn();
40-
console.warn = consoleWarn = jest.fn();
37+
console.error = jest.fn();
38+
console.log = jest.fn();
39+
console.warn = jest.fn();
4140
console.disableYellowBox = false;
4241
});
4342

4443
afterEach(() => {
4544
LogBox.uninstall();
4645
console.error = error;
46+
console.log = log;
4747
console.warn = warn;
4848
});
4949

@@ -329,6 +329,8 @@ describe('LogBox', () => {
329329
});
330330

331331
it('preserves decorations of console.error after installing/uninstalling', () => {
332+
const consoleError = console.error;
333+
332334
LogBox.install();
333335

334336
const originalConsoleError = console.error;
@@ -356,6 +358,8 @@ describe('LogBox', () => {
356358
});
357359

358360
it('preserves decorations of console.warn after installing/uninstalling', () => {
361+
const consoleWarn = console.warn;
362+
359363
LogBox.install();
360364

361365
const originalConsoleWarn = console.warn;

jest/mockNativeComponent.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,12 @@
1111

1212
const React = require('react');
1313

14+
let nativeTag = 1;
15+
1416
module.exports = viewName => {
1517
const Component = class extends React.Component {
18+
_nativeTag = nativeTag++;
19+
1620
render() {
1721
return React.createElement(viewName, this.props, this.props.children);
1822
}

0 commit comments

Comments
 (0)