Method “simulate” is meant to be run on 1 node. 0 found instead

非 Y 不嫁゛ 提交于 2020-05-15 09:04:05

问题


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

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

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.

The code before wrapping:

 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);
  });
});

code after wrapping:

 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);
  });
}); 

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


回答1:


.find('InputBase')

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

.find(InputBase)

Only CSS selector is expected to be used inside quotes.



来源:https://stackoverflow.com/questions/56921107/method-simulate-is-meant-to-be-run-on-1-node-0-found-instead

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!