Skip to content

Commit cbc279c

Browse files
NickGerlemanfacebook-github-bot
authored andcommitted
Fix Jest failure on console.error()
Summary: The version using `jest.spyOn()` stopped working at some point. Couldn't find any relevant setup changes, but this form seems to work. Changelog: [Internal] Reviewed By: christophpurrer Differential Revision: D43669469 fbshipit-source-id: 89d207117e9a56ae3374aed47a8a75fdf2e644fd
1 parent 1d8a6e3 commit cbc279c

File tree

2 files changed

+13
-21
lines changed

2 files changed

+13
-21
lines changed

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,7 @@ describe('TextInput compat with web', () => {
288288
'aria-label': 'label',
289289
'aria-labelledby': 'labelledby',
290290
'aria-level': 3,
291-
'aria-live': 'polite',
291+
// aria-live': 'polite', [TODO: https://github.com/facebook/react-native-deprecated-modules/pull/20]
292292
'aria-modal': true,
293293
'aria-multiline': true,
294294
'aria-multiselectable': true,
@@ -348,7 +348,6 @@ describe('TextInput compat with web', () => {
348348
aria-label="label"
349349
aria-labelledby="labelledby"
350350
aria-level={3}
351-
aria-live="polite"
352351
aria-modal={true}
353352
aria-multiline={true}
354353
aria-multiselectable={true}

jest/local-setup.js

Lines changed: 12 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -12,29 +12,22 @@
1212

1313
'use strict';
1414

15+
require('./setup');
16+
1517
const consoleError = console.error;
1618
const consoleWarn = console.warn;
1719

18-
jest.spyOn(console, 'debug').mockImplementation(() => {
19-
// Blackhole console output
20-
});
21-
22-
jest.spyOn(console, 'info').mockImplementation(() => {
23-
// Blackhole console output
24-
});
20+
// Blackhole verbose console output
21+
console.debug = jest.fn();
22+
console.info = jest.fn();
23+
console.log = jest.fn();
2524

26-
jest.spyOn(console, 'log').mockImplementation(() => {
27-
// Blackhole console output
28-
});
29-
30-
jest.spyOn(console, 'error').mockImplementation((...args) => {
25+
console.error = (...args) => {
3126
consoleError(...args);
32-
throw new Error('console.error() was called');
33-
});
27+
throw new Error('console.error() was called (see error above)');
28+
};
3429

35-
jest.spyOn(console, 'warn').mockImplementation((...args) => {
30+
console.warn = (...args) => {
3631
consoleWarn(...args);
37-
throw new Error('console.warn() was called');
38-
});
39-
40-
require('./setup');
32+
throw new Error('console.warn() was called (see warning above)');
33+
};

0 commit comments

Comments
 (0)