Skip to content

Commit

Permalink
Fix Jest failure on console.error()
Browse files Browse the repository at this point in the history
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
  • Loading branch information
NickGerleman authored and facebook-github-bot committed Mar 1, 2023
1 parent 1d8a6e3 commit cbc279c
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 21 deletions.
3 changes: 1 addition & 2 deletions Libraries/Components/TextInput/__tests__/TextInput-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ describe('TextInput compat with web', () => {
'aria-label': 'label',
'aria-labelledby': 'labelledby',
'aria-level': 3,
'aria-live': 'polite',
// aria-live': 'polite', [TODO: https://github.com/facebook/react-native-deprecated-modules/pull/20]
'aria-modal': true,
'aria-multiline': true,
'aria-multiselectable': true,
Expand Down Expand Up @@ -348,7 +348,6 @@ describe('TextInput compat with web', () => {
aria-label="label"
aria-labelledby="labelledby"
aria-level={3}
aria-live="polite"
aria-modal={true}
aria-multiline={true}
aria-multiselectable={true}
Expand Down
31 changes: 12 additions & 19 deletions jest/local-setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,29 +12,22 @@

'use strict';

require('./setup');

const consoleError = console.error;
const consoleWarn = console.warn;

jest.spyOn(console, 'debug').mockImplementation(() => {
// Blackhole console output
});

jest.spyOn(console, 'info').mockImplementation(() => {
// Blackhole console output
});
// Blackhole verbose console output
console.debug = jest.fn();
console.info = jest.fn();
console.log = jest.fn();

jest.spyOn(console, 'log').mockImplementation(() => {
// Blackhole console output
});

jest.spyOn(console, 'error').mockImplementation((...args) => {
console.error = (...args) => {
consoleError(...args);
throw new Error('console.error() was called');
});
throw new Error('console.error() was called (see error above)');
};

jest.spyOn(console, 'warn').mockImplementation((...args) => {
console.warn = (...args) => {
consoleWarn(...args);
throw new Error('console.warn() was called');
});

require('./setup');
throw new Error('console.warn() was called (see warning above)');
};

0 comments on commit cbc279c

Please sign in to comment.