fix: throw when no screens defined

This commit is contained in:
satyajit.happy
2019-07-29 00:50:43 +02:00
parent 1368b4fd20
commit 571c513eae
2 changed files with 23 additions and 0 deletions

View File

@@ -501,6 +501,23 @@ it('handles change in route names', () => {
});
});
it("throws if navigator doesn't have any screens", () => {
const TestNavigator = (props: any) => {
useNavigationBuilder(MockRouter, props);
return null;
};
const element = (
<NavigationContainer>
<TestNavigator />
</NavigationContainer>
);
expect(() => render(element).update(element)).toThrowError(
"Couldn't find any screens for the navigator. Have you defined any screens as its children?"
);
});
it('throws if navigator is not inside a container', () => {
const TestNavigator = (props: any) => {
useNavigationBuilder(MockRouter, props);

View File

@@ -87,6 +87,12 @@ export default function useNavigationBuilder<
{} as { [key: string]: object | undefined }
);
if (!routeNames.length) {
throw new Error(
"Couldn't find any screens for the navigator. Have you defined any screens as its children?"
);
}
const {
state: currentState,
getState: getCurrentState,