Javascript 1节点酶模拟
我在react native中有以下测试用例Javascript 1节点酶模拟,javascript,reactjs,react-native,jestjs,enzyme,Javascript,Reactjs,React Native,Jestjs,Enzyme,我在react native中有以下测试用例 it('changes text', () => { wrapper.find(InputBox).simulate('change', { target: { value: 'text Given' } }); }); 有2个输入框,所以这给了我一个错误,说“simulate应该在单个节点上运行,但找到了2” 如何解决此问题?您可以使用选择器,例如first或at。例如,假设您要选择第一个输入框,您将编写: wrapper
it('changes text', () => {
wrapper.find(InputBox).simulate('change', { target: { value: 'text Given' } });
});
有2个输入框,所以这给了我一个错误,说“simulate应该在单个节点上运行,但找到了2”
如何解决此问题?您可以使用选择器,例如
first
或at
。例如,假设您要选择第一个输入框
,您将编写:
wrapper.find(InputBox).first().simulate('change', { target: { value: 'text Given' } });
同样,您可以使用
last
获取最后一个匹配的节点,或at(index)
按索引选择匹配项。您可以使用选择器,例如first
或at
。例如,假设您要选择第一个输入框
,您将编写:
wrapper.find(InputBox).first().simulate('change', { target: { value: 'text Given' } });
同样,您可以使用last
获取最后一个匹配的节点,或使用at(index)
按索引选择匹配