Skip to content

Jest top-level await #1918

@veke

Description

@veke

Is there a way to configure "builder": "@angular-builders/jest:run" to support top-level awaits?

I've tested this with basic ng 19 setup and modified app component test a bit:

import { ComponentFixture, TestBed } from '@angular/core/testing';
const { AppComponent } = await import('./app.component');

describe('AppComponent', () => {
...
Jest encountered an unexpected token
SyntaxError: await is only valid in async functions and the top level bodies of modules

I have read through troubleshoots and tried various setups with transformer etc. with no luck.
Also used --experimental-vm-modules which produces different errors.

Anything to try?

Edit: I can run tests with dynamic imports using custom Jest setup without the builder. My idea is to reduce configuration needed when switching for this one.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions