首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >运行笑话时未处理的错误-木偶师测试

运行笑话时未处理的错误-木偶师测试
EN

Stack Overflow用户
提问于 2020-07-13 16:48:33
回答 2查看 1.8K关注 0票数 3

我正试着为我的木偶技师项目做测试。我遵循了一个基本指南,测试通过了,但是终端中有两个控制台错误。

使用 时不会出现错误。所以看起来这可能是特定网站的问题吗?

代码语言:javascript
复制
 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.

这是我的密码

代码语言:javascript
复制
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

代码语言:javascript
复制
module.exports = {
    preset: "jest-puppeteer",
    testMatch: [
      "**/test/**/*.test.js"
    ],
    verbose: true
}

package.json

代码语言:javascript
复制
{
  "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"
  }
}

我遇到的所有事情都提到了异步/等待的问题,但是我尝试过的任何事情都会产生同样的错误,如果不是的话,也会产生更多的错误。我用这些文件做了一个新的项目,我也收到了同样的错误。

EN

回答 2

Stack Overflow用户

发布于 2020-07-14 09:05:23

错误来自网站本身。检查网站的控制台。因此,对于像google.com或youtube.com这样的网站来说,它没有任何错误。

票数 0
EN

Stack Overflow用户

发布于 2020-09-17 09:18:44

我创造了干净的回购来复制问题。https://github.com/sergtimosh/jest-puppeteer-issue-reproduction.git

  • 克隆库
  • npm i
  • npm测试test.spec.js

  • HEADLESS=false npm试验test.spec.js

解决方法是在jest-environment.js.中创建匿名浏览器上下文。只需取消该文件中的两行注释,测试就会通过,没有任何问题。但是,如果您需要在测试套件(文件)之间共享浏览器上下文,问题仍然存在。

代码语言:javascript
复制
const PuppeteerEnvironment = require('jest-environment-puppeteer');


class JestEnvironment extends PuppeteerEnvironment {

  async setup() {
    await super.setup()
    //to fix issue uncomment next two lines
    // const incognitoContext = await this.global.browser.createIncognitoBrowserContext()
    // this.global.page = await incognitoContext.newPage()

  }

  async teardown() {
    await super.teardown()
  }

}

module.exports = JestEnvironment;

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/62880502

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档