相关疑难解决方法(0)

How to test a button click in React with TypeScript, Jest and Enzyme

I'm building a React Native app with TypeScript. I'm doing my component tests using Jest and Enzyme. I'm also using React Navigation

I'm struggling to write the unit test for clicking my button.

Here is the component's code (just the render function):

  render() {
    const { navigation } = this.props;
    return (
      <View style={styles.container}>
        <Button
          raised
          title={strings.painButtonTitle}
          buttonStyle={styles.painButton}
          titleStyle={styles.title}
          onPress={() => navigation.navigate("QuestionsScreen")}
        />
      </View>
    );
  }
Run Code Online (Sandbox Code Playgroud)

Now here is the unit test.

  describe("interaction", () => {
    let wrapper: ShallowWrapper;
    let …
Run Code Online (Sandbox Code Playgroud)

typescript jestjs react-native enzyme react-navigation

6
推荐指数
1
解决办法
7658
查看次数