[英]Using Jest with Puppeteer : EReferenceError : xxx is not defined
when learn puppeteer/jest, many tutorial articles example are the same,like:在学习 puppeteer/jest 的时候,很多教程文章的例子都是一样的,比如:
const timeout = 10000;
beforeAll(async () => {
await page.goto(URL, { waitUntil: "domcontentloaded" });
});
describe("Test title and header of the homepage", () => {
test("Title of the page", async () => {
const title = await page.title();
expect(title).toBe("Learn Web Development with free Classes and Tutorials - Sabe.io");
}, timeout);
test("Header of the page", async () => {
const h1Handle = await page.$("h1");
const html = await page.evaluate(h1Handle => h1Handle.innerHTML, h1Handle);
expect(html).toBe("Become a better developer");
}, timeout);
});
and the jest.config.js like:和 jest.config.js 之类的:
module.exports = {
preset: "jest-puppeteer",
globals: {
URL: "https://sabe.io"
},
testMatch: [
"**/test/**/*.test.js"
],
verbose: true
}
and they all success in article, but when i run that code on local, get an error :他们在文章中都成功了,但是当我在本地运行该代码时,出现错误:
ProtocolError: Protocol error (Page.navigate): Invalid parameters Failed to deserialize params.url - BINDINGS: mandatory field missing at position 49
or或者
ReferenceError: URL is not defined
does anybody get the same error ?有人得到同样的错误吗?
it success when jest.config.js chenge like this:当 jest.config.js 像这样变化时它成功:
module.exports = {
// preset: "jest-puppeteer", // remove that
globals: {
URL: "https://sabe.io"
},
testMatch: [
"**/test/**/*.test.js"
],
verbose: true
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.