Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix errors with component stacks reported as warnings #46637

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions packages/react-native/Libraries/LogBox/Data/LogBoxData.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,9 @@ let warningFilter: WarningFilter = function (format) {
return {
finalFormat: format,
forceDialogImmediately: false,
suppressDialog_LEGACY: true,
suppressDialog_LEGACY: false,
suppressCompletely: false,
monitorEvent: 'unknown',
monitorEvent: 'warning_unhandled',
monitorListVersion: 0,
monitorSampleRate: 1,
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ describe('LogBox', () => {
expect.stringMatching('at DoesNotUseKey'),
]);
expect(spy).toHaveBeenCalledWith({
level: 'warn',
level: 'error',
category: expect.stringContaining(
'Warning: Each child in a list should have a unique',
),
Expand Down Expand Up @@ -140,7 +140,7 @@ describe('LogBox', () => {
expect.stringMatching('at FragmentWithProp'),
]);
expect(spy).toHaveBeenCalledWith({
level: 'warn',
level: 'error',
category: expect.stringContaining('Warning: Invalid prop'),
componentStack: expect.anything(),
componentStackType: expect.stringMatching(/(stack|legacy)/),
Expand Down Expand Up @@ -236,7 +236,7 @@ describe('LogBox', () => {
),
]);
expect(spy).toHaveBeenCalledWith({
level: 'warn',
level: 'error',
category: expect.stringContaining('Warning: Manual console error'),
componentStack: expect.anything(),
componentStackType: 'stack',
Expand Down
39 changes: 39 additions & 0 deletions packages/react-native/Libraries/LogBox/__tests__/LogBox-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
}

describe('LogBox', () => {
const {error, log, warn} = console;

Check warning on line 34 in packages/react-native/Libraries/LogBox/__tests__/LogBox-test.js

View workflow job for this annotation

GitHub Actions / test_js (20)

'log' is assigned a value but never used

Check warning on line 34 in packages/react-native/Libraries/LogBox/__tests__/LogBox-test.js

View workflow job for this annotation

GitHub Actions / test_js (18)

'log' is assigned a value but never used

beforeEach(() => {
jest.resetModules();
Expand Down Expand Up @@ -506,6 +506,45 @@
'Custom: after installing for the second time',
);
});

it('registers errors with component stack as errors by default, when ExceptionManager is registered first', () => {
jest.spyOn(LogBoxData, 'checkWarningFilter');
jest.spyOn(LogBoxData, 'addLog');

ExceptionsManager.installConsoleErrorReporter();
LogBox.install();

console.error(
'HIT\n at Text (/path/to/Component:30:175)\n at DoesNotUseKey',
);

expect(LogBoxData.addLog).toBeCalledWith(
expect.objectContaining({level: 'error'}),
);
expect(LogBoxData.checkWarningFilter).toBeCalledWith(
'HIT\n at Text (/path/to/Component:30:175)\n at DoesNotUseKey',
);
});

it('registers errors with component stack as errors by default, when ExceptionManager is registered second', () => {
jest.spyOn(LogBoxData, 'checkWarningFilter');
jest.spyOn(LogBoxData, 'addLog');

LogBox.install();
ExceptionsManager.installConsoleErrorReporter();

console.error(
'HIT\n at Text (/path/to/Component:30:175)\n at DoesNotUseKey',
);

expect(LogBoxData.addLog).toBeCalledWith(
expect.objectContaining({level: 'error'}),
);
expect(LogBoxData.checkWarningFilter).toBeCalledWith(
'HIT\n at Text (/path/to/Component:30:175)\n at DoesNotUseKey',
);
});

it('registers errors without component stack as errors by default, when ExceptionManager is registered first', () => {
jest.spyOn(LogBoxData, 'checkWarningFilter');
jest.spyOn(LogBoxData, 'addException');
Expand Down
Loading