首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >找不到Jest puppeteer reference错误页面

找不到Jest puppeteer reference错误页面
EN

Stack Overflow用户
提问于 2020-09-30 22:21:26
回答 1查看 670关注 0票数 0

尝试使用puppeteer设置typescript jest

I按照下面提到的步骤进行操作

Jest-puppeteer with typescript configuration

有一个简单的测试

代码语言:javascript
复制
describe('Google', () => {
 
    beforeAll(async () => {
        await page.goto('https://google.com')
    })
 
    it('should display "google" text on page', async () => {
        await expect(page).toMatch('google')
    })
 
})

当我运行我的测试时,我得到奇怪的错误

代码语言:javascript
复制
ReferenceError: page is not defined

并且它指向beforeAll中的“await page”对象

我还注意到chrome试图启动,但没有启动,可能是这个错误是b/c chrome不能启动。

jest-puppeteer库负责启动浏览器并提供浏览器和页面对象

下面是取自上面链接中提到的页面的代码

代码语言:javascript
复制
//jest-puppeteer.config.js

let jest_puppeteer_conf = {
    launch: {
        timeout: 30000,
        dumpio: true // Whether to pipe the browser process stdout and stderr 
    }
}
 
const isDebugMode = typeof v8debug === 'object' || /--debug|--inspect/.test(process.execArgv.join(' '));
 
if (isDebugMode) {
    jest_puppeteer_conf.launch.headless = false; // for debug:  to see what the browser is displaying
    jest_puppeteer_conf.launch.slowMo = 250;  // slow down by 250ms for each step
    jest_puppeteer_conf.launch.devtools = true; // This lets you debug code in the application code browser
    jest_puppeteer_conf.launch.args = [ '--start-maximized' ]; // maximise the screen
}
 
module.exports = jest_puppeteer_conf;

在底部有一个小的调试部分,它提醒我添加以下类型我已经有了它们,仍然没有运气,任何帮助都很感激。

代码语言:javascript
复制
"compilerOptions": {
       .....
        "types": [
         .......
          "puppeteer",
          "jest-environment-puppeteer",
          "expect-puppeteer"
        ]
      }
EN

回答 1

Stack Overflow用户

发布于 2020-10-01 22:28:19

注释掉下面这一行可以解决这个问题。

代码语言:javascript
复制
// testEnvironment: "node"
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/64139611

复制
相关文章

相似问题

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