MyComponent等待firstInput
中的用户输入,而不是从Apollo查询中加载数据。它显示一些文本,并在完成后启用secondInput。
测试无法按我预期的那样工作-它仅在第一次渲染时渲染组件,并且即使我在renderResult上调用rerender,任何其他交互也不会触发任何事件。
如何使用React测试库和Jest测试这种交互?
const renderResult = render(
<AutoMockProvider>
<MyComponent/>
</AutoMockProvider>
)
const [firstInput, secondInput] = renderResult.container.querySelectorAll('input')
await userEvent.selectOptions(firstInput, 'NewSelection')
await userEvent.tab()
// wait for appearance
await waitFor(() => {
expect(renderResult.getByText('Expected text loaded by MyComponent after selction of firstInput')).toBeInTheDocument()
})
expect(secondInput).toBeEnabled()
是否可以使用React测试库测试该用例?还是我做错了什么,或者有错误的期望?