Reputation: 821
I am a newbie at running Jest puppeteer.
I'm trying to run a test suite locally that I did not write.
All the tests fail to run and I get this error pointing at beforeEach...
"beforeEach(async () => {"
"thrown: "Exceeded timeout of 5000 ms for a hook. Use jest.setTimeout(newTimeout) to increase the timeout value, if this is a long-running test.""
Where / how exactly should I place the setTimeout?
Is there something else I am missing or have in the wrong spot?
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.");
});
});
Thank you
Upvotes: 1
Views: 387
Reputation: 1472
You just need to place it on the top
const baseURL = "http://localhost:1234";
const puppeteer = require('puppeteer');
jest.setTimeout(500000);
beforeEach(() => {
// Reset mock function's states before each test.
jest.clearAllMocks();
});
....
Upvotes: 1