jest.setTimeout에 의해 지정된 5000ms 시간 초과 내에 비동기 콜백이 호출되지 않았습니다.
puppeteer와 jest를 사용하여 프런트 엔드 테스트를 실행하고 있습니다.
내 테스트는 다음과 같습니다.
describe("Profile Tab Exists and Clickable: /settings/user", () => {
test(`Assert that you can click the profile tab`, async () => {
await page.waitForSelector(PROFILE.TAB);
await page.click(PROFILE.TAB);
}, 30000);
});
때로는 테스트를 실행할 때 모든 것이 예상대로 작동합니다. 다른 경우에는 오류가 발생합니다.
Timeout - Async callback was not invoked within the 5000ms timeout specified by jest.setTimeout.
at node_modules/jest-jasmine2/build/queue_runner.js:68:21
at Timeout.callback [as _onTimeout] (node_modules/jsdom/lib/jsdom/browser/Window.js:633:19)
다음과 같은 이유로 이상합니다.
시간 초과를 30000으로 지정했습니다.
이 오류가 발생하는지 여부는 매우 무작위로 보입니다.
왜 이런 일이 일어나는지 추측 할 수 있습니까?
따라서 여기서 지정하는 시간 초과는 기본 시간 초과보다 짧아야합니다.
기본 시간 초과는 5000
이고 기본적으로 프레임 워크는 jasmine
입니다 jest
. 테스트 내부에 시간 초과를 추가하여 추가 할 수 있습니다
jest.setTimeout(30000);
그러나 이것은 테스트에만 해당됩니다. 또는 프레임 워크에 대한 구성 파일을 설정할 수 있습니다.
https://facebook.github.io/jest/docs/en/configuration.html#setuptestframeworkscriptfile-string
// jest.config.js
module.exports = {
setupTestFrameworkScriptFile: './jest.setup.js'
}
// jest.setup.js
jest.setTimeout(30000)
이 스레드도 참조
https://github.com/facebook/jest/issues/5055
https://github.com/facebook/jest/issues/652
async/await
테스트에서 비동기 일 때 호출해야합니다 .
describe("Profile Tab Exists and Clickable: /settings/user", () => {
test(`Assert that you can click the profile tab`, async () => {
await page.waitForSelector(PROFILE.TAB);
await page.click(PROFILE.TAB);
}, 30000);
});
Jest가 발전함에 따라이 질문에 대한 답변이 변경되었습니다. 현재 답변 (2019 년 3 월) :
에 세 번째 매개 변수를 추가하여 개별 테스트의 시간 초과를 무시할 수 있습니다
it
. 즉.it('runs slow', () => {...}, 9999)
을 사용하여 기본값을 변경할 수 있습니다
jest.setTimeout
. 이것을하기 위해:
// config
"setupFilesAfterEnv": [ // NOT setupFiles
"./src/jest/defaultTimeout.js"
],
과
// File: src/jest/defaultTimeout.js
/* global jest */
jest.setTimeout(1000)
- 다른 사람들이 지적했듯이 이것과 직접 관련
done
이없는 것은 async / await 접근법에는 필요하지 않습니다.
3000
테스트 시간이 초과 되어도 여전히 (임의로) 실패하는 경우가 있습니다.
Timeout - Async callback was not invoked within the 5000ms timeout specified by jest.setTimeout.
@Tarun의 훌륭한 답변 덕분에 많은 테스트를 해결하는 가장 짧은 방법은 다음과 같습니다.
describe('puppeteer tests', () => {
beforeEach(() => {
jest.setTimeout(10000);
});
test('best jest test fest', async () => {
// blah
});
});
Make sure to invoke done();
on callbacks or it won't simply pass the test.
beforeAll((done /* call it or remove it*/) => {
done(); // calling it
});
Applies to all other functions that have a done() callback.
I recently ran into this issue for a different reason: I was running some tests synchronously using jest -i
, and it would just timeout. For whatever reasoning, running the same tests using jest --runInBand
(even though -i
is meant to be an alias) doesn't time out.
Maybe this will help someone ¯\_(:/)_/¯
The timeout problem occurs when either network is slow or many network calls are made using await
, these scenarios exceed the default timeout i.e 5000ms. To avoid the timeout error simply increase the timeout of globals that support a timeout. A list of globals and their signature can be found here.
For Jest 24.9
For those who are looking an explanation about jest --runInBand
you can go to the documentation Running puppeteer in CI environments https://github.com/smooth-code/jest-puppeteer
'Programming' 카테고리의 다른 글
Android 에뮬레이터의 스토리지를 늘리는 방법은 무엇입니까? (0) | 2020.06.27 |
---|---|
delete []는 그것이 배열임을 어떻게 알 수 있습니까? (0) | 2020.06.27 |
Visual Studio에서 만든 Windows 서비스 설치 (0) | 2020.06.27 |
CSS로 전체 웹 페이지를 확장하려면 어떻게해야합니까? (0) | 2020.06.27 |
Java : 스트림의 올바른 문자 세트 인코딩을 결정하는 방법 (0) | 2020.06.27 |