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

Add mocks to fix: handleException is not a function (#29849) #30027

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
5 changes: 3 additions & 2 deletions Libraries/LogBox/Data/LogBoxData.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ import type {
import parseErrorStack from '../../Core/Devtools/parseErrorStack';
import type {ExtendedError} from '../../Core/Devtools/parseErrorStack';
import NativeLogBox from '../../NativeModules/specs/NativeLogBox';

const ExceptionsManager = require('../../Core/ExceptionsManager');
Copy link

@eliw00d eliw00d Oct 2, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was originally in reportLogBoxError to avoid a circular dependency. If you move it back into reportLogBoxError, but keep the mock in jest/setup, does it still solve the issue?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for taking a look. In my experience this change is necessary to avoid Jest throwing:

ReferenceError: You are trying to import a file after the Jest environment has been torn down.

I'm not sure how to resolve the circular dependency issue :\


export type LogBoxLogs = Set<LogBoxLog>;
export type LogData = $ReadOnly<{|
level: LogLevel,
Expand Down Expand Up @@ -98,8 +101,6 @@ export function reportLogBoxError(
error: ExtendedError,
componentStack?: string,
): void {
const ExceptionsManager = require('../../Core/ExceptionsManager');

error.forceRedbox = true;
error.message = `${LOGBOX_ERROR_MESSAGE}\n\n${error.message}`;
if (componentStack != null) {
Expand Down
7 changes: 7 additions & 0 deletions jest/setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,13 @@ jest
reportException: jest.fn(),
},
}))
.mock('../Libraries/Core/ExceptionsManager', () => {
return {
handleException: (...args) => {
return;
},
};
})
.mock('../Libraries/ReactNative/UIManager', () => ({
AndroidViewPager: {
Commands: {
Expand Down