等待酶的固定剂酶
下面我正在尝试进行使用component.setProps
的测试,如何等待useffect
在此之后运行< meowcomponent>
之后setProps
?
const history = createMemoryHistory();
history.push('/3');
const fetch = jest.fn()
const Component = mount(
<Router history={history}>
<Route path="/meow/:number">
<MeowComponent fetch={fetch} />
</Route>
</Router>
);
// This is the use case where component initially mounts
expect(fetch).toHaveBeenNthCalledWith(1, '3', false, false);
Component.setProps({ number: '2' });
// this fails because we haven't awaited the changes..
expect(fetch).toHaveBeenNthCalledWith(2, '2', false, false);
Below I'm trying to have a test that uses Component.setProps
, how to I await the useEffect
running within <MeowComponent>
after this setProps
?
const history = createMemoryHistory();
history.push('/3');
const fetch = jest.fn()
const Component = mount(
<Router history={history}>
<Route path="/meow/:number">
<MeowComponent fetch={fetch} />
</Route>
</Router>
);
// This is the use case where component initially mounts
expect(fetch).toHaveBeenNthCalledWith(1, '3', false, false);
Component.setProps({ number: '2' });
// this fails because we haven't awaited the changes..
expect(fetch).toHaveBeenNthCalledWith(2, '2', false, false);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试:
测试结果:
Try:
Test result: