[英]jest puppeteer how to use setTimeout
我是運行 Jest puppeteer 的新手。
我正在嘗試在本地運行我沒有編寫的測試套件。
所有測試都無法運行,我得到這個錯誤指向 beforeEach ...
"beforeEach(async () => {"
“拋出:”超過 5000 毫秒的鈎子超時。 如果這是一個長時間運行的測試,請使用 jest.setTimeout(newTimeout) 增加超時值。""
我應該在哪里/如何准確放置 setTimeout?
我還有什么遺漏或在錯誤的地方嗎?
const baseURL = "http://localhost:1234";
const puppeteer = require('puppeteer');
beforeEach(() => {
// Reset mock function's states before each test.
jest.clearAllMocks();
});
describe("chatbot", () => {
beforeEach(async () => {
const browser = await puppeteer.launch({headless: false, slowMo: 250,});
const page = await browser.newPage();
await page.goto(baseURL, { waitUntil: "load" });
// set the fade-ins to 0 ms to prevent timeouts in tests
await page.evaluate(() => { window.animationDelay = 0 })
await page.click("#chat-circle");
await browser.close()
});
it("should show contact info when the user enters 'contact'", async () => {
// submit the form with a message, expect to see the response
const message = "contact";
await page.evaluate(() => {
// get this same const in the page's context
const message = "contact";
$("#chat-input").val(message)
});
await page.click("#chat-submit");
await expect(page).toMatch("We have 24 hour phone support. Our phone number is +01 312 555 8432. We look forward to hearing from you!");
});
it("should show credit card help message when the user enters 'credit card'", async () => {
// submit the form with a message, expect to see the response
const message = "credit card";
await page.evaluate(() => {
// get this same const in the page's context
const message = "credit card";
$("#chat-input").val(message)
});
await page.click("#chat-submit");
await expect(page).toMatch("You can pay with any major credit card. Enter your card details and billing address at checkout.");
});
it("should show payment help message when the user enters 'payment'", async () => {
// submit the form with a message, expect to see the response
const message = "payment";
await page.evaluate(() => {
// get this same const in the page's context
const message = "payment";
$("#chat-input").val(message)
});
await page.click("#chat-submit");
await expect(page).toMatch("We have three payment options: credit card, paypal, or apple pay. Choose your preferred method at checkout.");
});
it("should show help options when the users enters 'help'", async () => {
// submit the form with a message, expect to see the response
const message = "help";
await page.evaluate(() => {
// get this same const in the page's context
const message = "help";
$("#chat-input").val(message)
});
await page.click("#chat-submit");
await expect(page).toMatch("Enter a keyword for help with a topic: contact, payment, credit card, destinations.");
});
});
謝謝
你只需要把它放在頂部
const baseURL = "http://localhost:1234"; const puppeteer = require('puppeteer'); jest.setTimeout(500000); beforeEach(() => { // Reset mock function's states before each test. jest.clearAllMocks(); }); ....
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.