Click here to Skip to main content
15,883,705 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Can anyone sense the cause of this error for the below code ?

TypeError: Cannot read property 'close' of null

    18 |
    19 |   afterAll(async () => {
  > 20 |     await browser.close();



(Please don't mind the style, as a Javascript mixture of Jest and Puppeteer):

let browser = null;

describe('Load page', () => {

  beforeAll(async () => { 
    browser = await puppeteer.launch({ 
      headless: false    
    });

  });

  afterAll(async () => {
    browser.close();
  });


What I have tried:

I put an
await
before
browser.close()
, but it doesn't solve the problem (or make too much sense):

afterAll(async () => {
    browser.close();
  });
Posted
Updated 12-Aug-21 1:26am
Comments
Richard MacCutchan 12-Aug-21 7:27am    
You are trying to call close on a null reference. Use the debugger to see why the variable does not refer to an object.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900