gpt4 book ai didi

jestjs - 运行 jest-puppeteer 测试时未处理的错误

转载 作者:行者123 更新时间:2023-12-05 07:04:43 25 4
gpt4 key购买 nike

我正在尝试为我的 puppeteer 操纵者项目设置测试。我按照基本指南进行操作并且测试通过,但终端中出现 2 个控制台错误。

使用 https://google.com 时没有出现错误或 https://youtube.com 。所以它看起来可能与特定站点有关?

 console.error
Unhandled error

at process.uncaught (node_modules/jest-jasmine2/build/jasmine/Env.js:248:21)
at handler (node_modules/jest-environment-puppeteer/lib/PuppeteerEnvironment.js:17:11)
at map (node_modules/mitt/src/index.ts:74:75)
at Array.map (<anonymous>)
at Object.emit (node_modules/mitt/src/index.ts:74:56)
at Page.emit (node_modules/puppeteer/lib/EventEmitter.js:72:22)

console.error

at process.uncaught (node_modules/jest-jasmine2/build/jasmine/Env.js:249:21)
at handler (node_modules/jest-environment-puppeteer/lib/PuppeteerEnvironment.js:17:11)
at map (node_modules/mitt/src/index.ts:74:75)
at Array.map (<anonymous>)
at Object.emit (node_modules/mitt/src/index.ts:74:56)
at Page.emit (node_modules/puppeteer/lib/EventEmitter.js:72:22)

Test Suites: 1 passed, 1 total
Tests: 1 passed, 1 total
Snapshots: 0 total
Time: 5.613 s
Ran all test suites.

这是我的代码

describe('NCAA Home', () => {
beforeAll(async () => {
await page.goto('http://stats.ncaa.org/rankings/change_sport_year_div');
});

it('should be titled "NCAA Statistics"', async () => {
await expect(page.title()).resolves.toMatch('NCAA Statistics');
});
});

这是我的 jest.config.js

module.exports = {
preset: "jest-puppeteer",
testMatch: [
"**/test/**/*.test.js"
],
verbose: true
}

包.json

{
"name": "stackoverflow",
"version": "1.0.0",
"description": "",
"main": "index.js",
"jest": {
"preset": "jest-puppeteer"
},
"scripts": {
"test": "jest"
},
"author": "",
"license": "ISC",
"devDependencies": {
"jest": "^26.1.0",
"jest-puppeteer": "^4.4.0"
},
"dependencies": {
"puppeteer": "^5.1.0"
}
}

我遇到的所有事情都提到了 async/await 的问题,但我尝试过的任何事情都会产生相同的错误,如果不是,还会产生更多的错误。我用这些文件创建了一个新项目,但我遇到了同样的错误

最佳答案

错误来自网站本身。检查网站的控制台。因此,对于像 google.com 或 youtube.com 这样的网站,它可以正常运行。

enter image description here

关于jestjs - 运行 jest-puppeteer 测试时未处理的错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62880502/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com