React / Jest / TestRenderer:如何将模拟的组件传递给经过测试的组件?

时间:2019-09-24 09:29:14

标签: reactjs react-native mocking jestjs

我有一个看起来像这样的组件:

const MyComponent = ({ anotherComponent = null }) => {
  return (
    <View>
      {anotherComponent}
      <Text>{anotherComponent? "with anotherComponent" : "without anotherComponent"}</Text>
    </View>
  );
};

如何模拟AnotherComponent,以便我可以将模拟传递给MyComponent?

你能做这样的事情吗:  const anotherComponent = jest.mock("../src/AnotherComponent", () => "AnotherComponent");,然后将anotherComponent传递给MyComponent吗?

0 个答案:

没有答案