From 80486cb2c1fdf785ceae2cf3433655ea812cd21d Mon Sep 17 00:00:00 2001 From: Nir Yosef Date: Wed, 13 Jul 2022 19:40:43 +0300 Subject: [PATCH 1/2] [NavigationMock] throw informative error on missing component --- lib/Mock/Components/NavigationButton.tsx | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/lib/Mock/Components/NavigationButton.tsx b/lib/Mock/Components/NavigationButton.tsx index b91d67a11eb..17dd38a6b7d 100644 --- a/lib/Mock/Components/NavigationButton.tsx +++ b/lib/Mock/Components/NavigationButton.tsx @@ -32,10 +32,12 @@ export const NavigationButton = class extends Component { renderButtonComponent() { const { button, componentId } = this.props; - //@ts-ignore const buttonComponentId = button.component!.componentId; - //@ts-ignore - const Component = Navigation.mock.store.getComponentClassForName(button.component.name)!(); + const ComponentClass = Navigation.mock.store.getComponentClassForName(button.component.name); + if (!ComponentClass) { + throw new Error(`Cannot find registered component for: ${button.component.name}`); + } + const ButtonComponent = ComponentClass(); const props = Navigation.mock.store.getPropsForId(buttonComponentId); return ( { }} testID={button.testID} > - Date: Wed, 13 Jul 2022 20:03:09 +0300 Subject: [PATCH 2/2] fix tsc --- lib/Mock/Components/NavigationButton.tsx | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/Mock/Components/NavigationButton.tsx b/lib/Mock/Components/NavigationButton.tsx index 17dd38a6b7d..06d80162b83 100644 --- a/lib/Mock/Components/NavigationButton.tsx +++ b/lib/Mock/Components/NavigationButton.tsx @@ -32,10 +32,12 @@ export const NavigationButton = class extends Component { renderButtonComponent() { const { button, componentId } = this.props; + // @ts-ignore const buttonComponentId = button.component!.componentId; + // @ts-ignore const ComponentClass = Navigation.mock.store.getComponentClassForName(button.component.name); if (!ComponentClass) { - throw new Error(`Cannot find registered component for: ${button.component.name}`); + throw new Error(`Cannot find registered component for: ${button.component?.name}`); } const ButtonComponent = ComponentClass(); const props = Navigation.mock.store.getPropsForId(buttonComponentId);