问题描述
试图用操纵up来设置打字稿玩笑
我按照以下逐步说明进行操作
Jest-puppeteer with typescript configuration
有一个简单的测试
describe('Google',() => {
beforeAll(async () => {
await page.goto('https://google.com')
})
it('should display "google" text on page',async () => {
await expect(page).toMatch('google')
})
})
运行测试时出现奇怪的错误
ReferenceError: page is not defined
,它指向beforeAll内部的“等待页面”对象
我还注意到chrome尝试加入,但没有启动,可能是因为此错误是b / c chrome无法启动。
jest-puppeteer库负责启动浏览器并提供浏览器和页面对象
//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;
底部有一个小的调试部分,提醒您添加以下我已经拥有的类型,但仍然没有运气,我们将提供任何帮助。
"compilerOptions": {
.....
"types": [
.......
"puppeteer","jest-environment-puppeteer","expect-puppeteer"
]
}
解决方法
注释以下行可解决此问题。
// testEnvironment: "node"