Search code examples
javascriptjestjsplaywright

Jest Test Error: browserType.launch: setImmediate is not defined. While using Playwright


I am getting an error while testing with jest in my Javascript code.

The Error:

FAIL src/test/testPlaywright.test.jsx (5.779 s) × Creating a Snapshot of interacting with playwright (149 ms)

● Creating a Snapshot of interacting with playwright

browserType.launch: setImmediate is not defined

  4 |     for(const browserType of [chromium, firefox, webkit]){
  5 |         console.log("Testing");
> 6 |         const browser = await browserType.launch({headless: false});
    |                                           ^
  7 |         const page = await browser.newPage();
  8 |         await page.setDefaultNavigationTimeout(1000000);
  9 |         await page.goto('https://app.wien.gv.at/navigation/', { waitUntil: 'networkidle' });

  at Object.<anonymous> (src/test/testPlaywright.test.jsx:6:43)

Test Suites: 1 failed, 1 total Tests: 1 failed, 1 total Snapshots: 0 total Time: 8.517 s Ran all test suites related to changed files.

The Code:

import { chromium, webkit, firefox } from "playwright";

test('Creating a Snapshot of interacting with playwright',async()=>{
    for(const browserType of [chromium, firefox, webkit]){
        console.log("Testing");
        const browser = await browserType.launch({headless: false});
        const page = await browser.newPage();
        await page.setDefaultNavigationTimeout(1000000); 
        await page.goto('https://app.wien.gv.at/navigation/', { waitUntil: 'networkidle' });

        await page.click("(//mat-icon[text()='keyboard_arrow_down'])[1]")
        await page.click("#mat-select-0")
        await page.click('//span[@class="mat-option-text"][contains(.,"Veranstaltungszentrum")]')
        await page.click("//mat-icon[text()='keyboard_arrow_up']")
        
        await page.click("(//mat-icon[text()='keyboard_arrow_down'])[2]")
        await page.click("#mat-select-3")
        await page.click('//span[@class="mat-option-text"][contains(.,"Kapelle Krankenhaus Hietzing")]')

        await page.waitForTimeout(2000);

        await page.screenshot({path:'image-'+browserType.name()+'.png'});
        
        await browser.close();
    }
})

Solution

  • The Problem is the setImmediate function.

    I just added the polyfill.js in my test class : import 'core-js'; after that setImmediate was defined again and works now as intended.