Skip to content

fix: make sure we don't swallow errors inside the mock #7899

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

Merged
merged 4 commits into from
Aug 13, 2024
Merged
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
6 changes: 4 additions & 2 deletions lib/Mock/Components/LayoutComponent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,10 @@ export const LayoutComponent = class extends Component<ComponentProps> {
return <View />;
}
componentDidCatch(error: Error, errorInfo: React.ErrorInfo) {
throw new Error(
`Error while trying to render layout ${this.props.layoutNode.nodeId} of type ${this.props.layoutNode.type}: ${error}\n${errorInfo?.componentStack}`
const err = new Error(
`Error while trying to render layout ${this.props.layoutNode.nodeId} of type ${this.props.layoutNode.type}: ${error}\n${errorInfo?.componentStack}`,
);
(err as any).cause = error;
throw err;
}
};
4 changes: 3 additions & 1 deletion lib/src/adapters/NativeEventsReceiver.mock.ts
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
export const { NativeEventsReceiver } = jest.genMockFromModule('./NativeEventsReceiver');
export const { NativeEventsReceiver } = jest.genMockFromModule(
'./NativeEventsReceiver'
) as typeof import('./NativeEventsReceiver');
4 changes: 3 additions & 1 deletion lib/src/events/EventsRegistry.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ describe('EventsRegistry', () => {
it('exposes appLaunched event', () => {
const subscription = {};
const cb = jest.fn();
mockNativeEventsReceiver.registerAppLaunchedListener.mockReturnValueOnce(subscription);
(mockNativeEventsReceiver.registerAppLaunchedListener as jest.MockedFunction<
any
>).mockReturnValueOnce(subscription);

const result = uut.registerAppLaunchedListener(cb);

Expand Down
5 changes: 1 addition & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,6 @@
"release": "node ./scripts/release",
"lint": "eslint --ext .js,.jsx,.ts,.tsx ./"
},
"overrides": {
"@babel/traverse": "7.22.6"
},
"peerDependencies": {
"react": "*",
"react-native": "*",
Expand Down Expand Up @@ -125,7 +122,7 @@
"shell-utils": "1.x.x",
"ts-mockito": "^2.3.1",
"typedoc": "0.x.x",
"typescript": "4.4.3"
"typescript": "5.5.4"
},
"husky": {
"hooks": {
Expand Down
Loading