Jest puppeteer typescript reference error Page not found

2.4k views Asked by At

Trying to setup typescript jest with puppeteer

i following step by step instructions as mentioned below

Jest-puppeteer with typescript configuration

there is a simple test

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

when i run my test i get weird error

ReferenceError: page is not defined

and it is pointing to the 'await page' object inside beforeAll

i also notice chrome try to kick in and but does not launch may be this error is b/c chrome could not launch.

jest-puppeteer library is responsible for launching a browser and providing browser and page objects

and here is the code taken from the page mentioned above in link

//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;

there is a small debug section at the bottom which reminds to add following types i already have them and still no luck, any help is appreciated.

"compilerOptions": {
       .....
        "types": [
         .......
          "puppeteer",
          "jest-environment-puppeteer",
          "expect-puppeteer"
        ]
      }
1

There are 1 answers

0
d-man On

commenting out the following line fix the issue.

// testEnvironment: "node"