reactjs - 增加 jest.setTimeout() 是一个好习惯吗?
问题描述
我有一个案例,我正在像这样在 Jest 文件中模拟 API Put 请求。
....
....
const mockSocialPostUpdate = jest
.spyOn(api, "put")
.mockImplementation(() => Promise.resolve());
await waitFor(() => {
expect(mockSocialPostUpdate).toHaveBeenCalledWith(
expect.objectContaining({ path: "/api/v1/social-posts/:id" }),
{ id: postContent.id },
{
id: postContent.id,
text: updatedDelta
}
);
});
我不知道为什么,但只有在我得到的这个测试文件中
Async callback was not invoked within the 5000 ms timeout specified by jest.setTimeout.Timeout - Async callback was not invoked within the 5000 ms timeout specified by jest.setTimeout.Error:
现在唯一可行的解决方案是 putjest.setTimeout(30000);
但我不确定这是否是最佳实践。我如何调查为什么我会收到此测试的超时错误。我正在做 console.logs 并且 Put 请求正在发生,我正在达到await WaitFor()
功能
解决方案
推荐阅读
- java - Esper引擎:我不能在'inner join on'之后使用'<'或'>'吗?
- spring-boot - 在 Intellij IDEA 中将 vaadin 添加到 Spring Boot 项目时出错
- mysql - 错误:命令'C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\BuildTools\\VC\\Tools\\MSVC\\14.25.28610\\bin\\HostX86\\x86\\cl 。可执行程序'
- javascript - 有人可以解释为什么我需要在 2 个不同的函数中使用 await 来获取 json 吗?
- python - AttributeError:'int'对象在抓取维基百科时没有属性'parent'
- java - Pojo验证的Spring Boot Pojo不起作用
- python - paramiko.ssh_exception.SSHException client.connect 格式
- python - Python数据框 - 计算指定范围内的出现次数(不是轴!)
- angular - Angular 对抗 XSS
- git - 将更改推送到 git 存储库中的主分支时出错