Jest-puppeteer: How to fix TS2339: Property 'browser' does not exist on type 'Global'?

Created on 5 Apr 2019  ·  6Comments  ·  Source: smooth-code/jest-puppeteer

Dear jest-puppeteer community,

I am using typescript and configured jest-puppeteer using next configuration:
(without configuring custom setup and teardown)

jest-puppeteer.config.js

module.exports = {
    launch: {
        headless: false,
    }
}

jest.breakpoints.config.js

module.exports = {
    preset: 'jest-puppeteer',
    testRegex: './breakpoints/',
}

And test file:

beforeAll(async () => {
    //  Getting TS2339: Property 'browser' does not exist on type 'Global
    page = await global.browser.newPage();
    script = `getComputedStyle(document.querySelector('img[alt="Google"]', null)).display`;
});

afterAll(async () => {
    await page.close();
});

describe('Breakpoint test', () => {
    it('should not display right nav at mobile breakpoint', async () => {
        page.setViewport({ width: 400, height: 600 });
        await page.goto('https://www.google.com/');
        const result = await page.evaluate(script);
        expect(result).not.toBeNull()
    }, 10000);
});

And it works. but I am getting this TS2339 tslint error. Could someone, please, help me to understand how to fix it without disabling TS-lint on this line.

Thank you!

help wanted 🆘 question ❓ typings 🔧

All 6 comments

Hello @sinapsist, I don't know Typescript but I am sure someone would be able to help you.

it's not an elegant solution, but you can add this line to solve this problem.

declare var global: any

by the way, Should we add some Declaration Files(d.ts)? Its very useful. @neoziro

@xiaoyuhen if you are up to maintain it, yes it could be great. On my side, I don't use Typescript and I can't edit any Typescript file.

@neoziro

yeah, I create an issue to about that https://github.com/smooth-code/jest-puppeteer/issues/224

@sinapsist You can get TS definition for jest-puppeteer from this package: https://www.npmjs.com/package/@types/jest-environment-puppeteer

Was this page helpful?
0 / 5 - 0 ratings

Related issues

tkrotoff picture tkrotoff  ·  4Comments

undrafted picture undrafted  ·  4Comments

rodoabad picture rodoabad  ·  3Comments

igneel64 picture igneel64  ·  5Comments

melissachang picture melissachang  ·  6Comments