我知道我可以使用jest.setTimeout()
为测试设置自定义超时。我在下面这样做。
MINUTE
的值为60 * 1000
。为什么Jest不应用我的超时?
thrown: "Exceeded timeout of 5000 ms for a test.
Use jest.setTimeout(newTimeout) to increase the timeout value, if this is a long-running test."
13 |
14 | describe(`integration with API provider`, () => {
> 15 | it(`works`, async () => {
| ^
16 | // Just in case network is slow.
17 | jest.setTimeout(1 * MINUTE);
正如您所看到的(尽管在SO的其他地方声明了什么),您不能通过从内部调用jest.setTimeout
来更改单个测试的超时。注意你引用的文档状态(强调我的):
这只影响测试文件
用于测试发现时间,而不是执行时间,为给定上下文设置超时。超时是在测试回调调用之前设置的,一旦测试实际开始,您就不能更改它。
对于单个测试,您可以通过向test
/it
函数(或在其上定义的各种帮助器)传递第三个参数来设置超时,例如:
it("has a description", () => {
// ...
}, 60_000);