方法“模拟”旨在在1个节点上运行。找到0个代替 [英] Method “simulate” is meant to be run on 1 node. 0 found instead

查看:142
本文介绍了方法“模拟”旨在在1个节点上运行。找到0个代替的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近将组件包装在ThemeProvider的测试中。当我运行测试时,它会引发以下错误

I have recently wrapped my component in test with ThemeProvider. When I ran my tests it's throwing the following error


’方法模拟应在1个节点上运行。而是找到了0个。

'Method "simulate" is meant to be run on 1 node. 0 found instead'

在包装之前,它可以正常工作。我该如何解决这个问题?我在GitHub中发现了许多与此类似的问题,并且我尝试了所有这些方式,但仍然遇到相同的错误。

Before wrapping it was working fine. How can I resolve this issue? I found many issues similar to this in GitHub and I tried all those ways still I'm getting the same error.

包装前的代码:

 test('handleSelect function called on option select', () => {
    const handleSelectSpy = sinon.spy();
    wrapper = mount( 
        <Dropdown handleSelect={handleSelectSpy} options={options} />
    );
    dropdown = wrapper.find('Dropdown');
    dropdown
      .find('InputBase')
      .find('[role="button"]')
      .simulate('click');
    expect(true).toBe(true);
  });
});

包装后的代码:

 test('handleSelect function called on option select', () => {
    const handleSelectSpy = sinon.spy();
    wrapper = mount(
      <ThemeProvider>
        <Dropdown handleSelect={handleSelectSpy} options={options} />
      </ThemeProvider>,
    );
    dropdown = wrapper.find('Dropdown');
    dropdown
      .find('InputBase')
      .find('[role="button"]')
      .simulate('click');
    expect(true).toBe(true);
  });
}); 

错误:
下拉菜单-完整DOM渲染›在选项select $ b $上调用的handleSelect函数b方法模拟旨在在1个节点上运行。而是找到0。

Error: Dropdown - Full DOM rendering › handleSelect function called on option select Method "simulate" is meant to be run on 1 node. 0 found instead.

推荐答案

.find('InputBase')

如果这是组件类名/构造函数,则应不带引号:

if this is a component classname/constructor function it should be without quotes:

.find(InputBase)

仅CSS选择器预计将在引号内使用。

Only CSS selector is expected to be used inside quotes.

这篇关于方法“模拟”旨在在1个节点上运行。找到0个代替的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆