简体   繁体   English

1个节点的酶模拟

[英]Enzyme simulate with 1 node

I have the following test case in react-native. 我在本机中有以下测试用例。

  it('changes text', () => {
    wrapper.find(InputBox).simulate('change', { target: { value: 'text Given' } });
  });

There are 2 InputBoxes so this gives me an error saying 'simulate should run on a single node, but found 2'. 有2个InputBoxes,所以这给我一个错误:“模拟应在单个节点上运行,但找到2个”。

How can I fix this issue? 如何解决此问题?

You could make use of selectors such as first or at . 您可以使用选择器,例如firstat For instance, say you want to select the first InputBox , you will write: 例如,假设您要选择第一个InputBox ,您将编写:

 wrapper.find(InputBox).first().simulate('change', { target: { value: 'text Given' } });

In the same way you can use last to get the last of matched nodes or at(index) to select matches by index. 以相同的方式,您可以使用last获取最后一个匹配的节点,也可以使用at(index)通过索引选择匹配项。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM