angular-builders icon indicating copy to clipboard operation
angular-builders copied to clipboard

Jest top-level await

Open veke opened this issue 8 months ago • 0 comments

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.

veke avatar Apr 16 '25 10:04 veke