我有一个来自react-navigation
的堆栈导航器,它与screenProps
嵌套在另一个组件中。
const AuthNavigator = createStackNavigator(
{
AuthSMSPhoneEntryConnected,
AuthSMSVerificationConnected,
AuthPassword,
},
{
initialRouteName: 'AuthSMSPhoneEntryConnected',
headerMode: 'none',
navigationOptions: { header: null },
}
);
const Auth = (props) => {
const emailRequired = props.navigation.getParam('emailRequired', true);
return <AuthNavigator {...props} screenProps={{ emailRequired, ...props }} />;
};
我需要使用Jest渲染组件的快照...
describe('Auth component', () => {
it('should render', () => {
const navigation = { getParam: jest.fn(() => true) };
const tree = renderer.create(<Auth navigation={navigation} />).toJSON();
expect(tree).toBeTruthy();
});
});
...但收到错误:TypeError: Cannot read property 'routes' of undefined