Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jest Puppeteer - Setup Visual Studio Code for it

I'm planning to setup env for testing in Visual Studio Code IDE. The problem that I have is that VS Code in any XXX.test.js file don't know what is browser or page variable. I'm receiving such errors:

'page' is not defined.eslint(no-undef)

Is this something related only to IDE that I'm using? Some plugin from this IDE? Or maybe it is normal for jest-puppeteer and I need to get used to it?

The whole test when it runs works ok but it seems that IDE only don't know what is page.

I'm working right now on this simple example and I'm just learning this but I'm trying to setup env for it in the same time. My Network.test.js file looks like this. No imports or require at all at the top of the file.

describe("Google", () => {
    beforeAll(async () => {
        await page.goto("https://google.com");
    });

    it('should display "google" text on page', async () => {
        await expect(page).toMatch("google");
    });
});

Later I need to switch it to Typescript which I think will be also a challenge. Now I just want to focus on pure javascript approach.

How to get rid of this IDE errors that are not errors in reality?

like image 498
Marcin Kapusta Avatar asked Jul 06 '26 07:07

Marcin Kapusta


1 Answers

Add the Puppeteer globals, Page and Browser, to your ESLint config.

Then, add the following to your .eslintrc file:

env: {
    jest: true,
},
// Puppeteer globals
globals: {
    page: true,
    browser: true,
},

See Here : Link

like image 70
AustinCo Avatar answered Jul 09 '26 00:07

AustinCo



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!