【发布时间】:2019-07-07 09:59:34
【问题描述】:
我最近使用 ThemeProvider 将我的组件包装在测试中。当我运行测试时,它会抛出以下错误
'方法“模拟”意味着在 1 个节点上运行。找到了 0 个'
在包装之前它工作正常。我该如何解决这个问题?我在 GitHub 中发现了许多类似的问题,我尝试了所有这些方法,但仍然遇到相同的错误。
包装前的代码:
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 渲染 › 选项选择时调用的 handleSelect 函数 方法“模拟”意味着在 1 个节点上运行。找到了 0 个。
【问题讨论】: