Hi all,
I just start to use Jest and Puppeteer.
I dont know if my issue is related to jest or to vscode.
As you can see in the associated screenshots, I use jest and puppeteer.
I declare two variables browser and page and I initialize them in the beforeAll block.
However, the other blocks (afterAll et it) seem to ignore the types of these variables.
It show only Any and it does not suggest methods of the related variables (when typing CTRL + space).
Any idea how can I resolve this please?
Does exist something to configure?


@fzalila this issue is not related to jest. However, the reason you're seeing any here is that because the variables (e.g. browser) are declared without any assignments, so the editor cannot infer those types.
I'm assuming you're not using TypeScript. In that case, you can declare type annotations via a jsdoc @type comment:
import puppeteer from 'puppeteer';
describe('Describe block', () => {
/** @type {puppeteer.Browser} */
let browser;
/** @type {puppeteer.Page} */
let page;
beforeAll(async function () {
browser = await puppeteer.launch();
page = await browser.newPage();
});
it('works!', () => {
// you should be able to get type completions here
browser
page
})
})
If that didn't work, make sure you add @types/puppeteer to your devDependencies.
Thank you @wsmd! It perfectly works!
Most helpful comment
@fzalila this issue is not related to jest. However, the reason you're seeing
anyhere is that because the variables (e.g.browser) are declared without any assignments, so the editor cannot infer those types.I'm assuming you're not using TypeScript. In that case, you can declare type annotations via a jsdoc
@typecomment:If that didn't work, make sure you add
@types/puppeteerto yourdevDependencies.