【问题标题】:How to select an element (Text, View) in react-native with jest+enzyme (mostly when Text/View are nested deep-down in the component)?如何使用 jest+enzyme 在 react-native 中选择一个元素(文本、视图)(主要是当文本/视图嵌套在组件的深处时)?
【发布时间】:2021-12-26 14:26:34
【问题描述】:

我知道酶中有一种叫做find 的东西,但我想知道如何通过某些属性选择反应原生元素

【问题讨论】:

    标签: react-native jestjs enzyme jest-enzyme


    【解决方案1】:

    您可以通过id等任何属性选择它,例如,

    用于在testing.js中选择以下文本

    <Text id="myid">hello </Text>
    

    您可以执行以下操作

    it('selects Text with id attr', () => {
      let wrapper = shallow(<Testing />);
      let text = wrapper.findWhere(node => node.name() === 'Text' && node.prop('id') === 'myid');
      console.log(text.debug());
    })
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-11-11
      • 1970-01-01
      • 2017-04-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多