用Jest

时间:2019-08-27 20:20:16

标签: react-native jestjs react-navigation

我有一个来自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

0 个答案:

没有答案