mirror of
https://github.com/zhigang1992/react-navigation.git
synced 2026-03-06 22:39:41 +08:00
fix: throw when no screens defined
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user