Open
Description
Command
test
Is this a regression?
- Yes, this behavior used to work in the previous version
The previous version in which this bug was not present was
No response
Description
When testing a component that uses @defer (on timer(2s))
, switching the tests to use AoT makes the test fails.
Minimal Reproduction
Generate a new app with latest CLI and add a component:
npx @angular/cli@20.0.0-next.9 new defer-aot-repro --defaults --no-routing
cd defer-aot-repro
ng g c user
Use app-user in app.html:
@defer (on timer(2s)) {
<app-user />
}
Change the test to:
import { fakeAsync, TestBed, tick } from '@angular/core/testing';
import { App } from './app';
describe('App', () => {
beforeEach(async () => {
await TestBed.configureTestingModule({
imports: [App],
}).compileComponents();
});
it('should render user', fakeAsync(() => {
const fixture = TestBed.createComponent(App);
fixture.detectChanges();
tick(2000);
const compiled = fixture.nativeElement as HTMLElement;
expect(compiled.querySelector('p')?.textContent).toContain('user works');
}));
});
Run:
ng test --no-watch --code-coverage
Tests are OK 👍
Edit angular.json to add "aot": true in the test section and run:
ng test --no-watch --code-coverage
The test is failing:
Chrome Headless 135.0.0.0 (Mac OS 10.15.7) App should render user FAILED
Expected undefined to contain 'user works'.
Exception or Error
Your Environment
Angular CLI: 20.0.0-next.9
Node: 22.14.0
Package Manager: npm 10.9.0
OS: darwin arm64
Angular: 20.0.0-next.9
... build, cli, common, compiler, compiler-cli, core, forms
... platform-browser, router
Package Version
------------------------------------------------------
@angular-devkit/architect 0.2000.0-next.9
@angular-devkit/core 20.0.0-next.9
@angular-devkit/schematics 20.0.0-next.9
@schematics/angular 20.0.0-next.9
rxjs 7.8.2
typescript 5.8.3
zone.js 0.15.0
Anything else relevant?
No response
Metadata
Metadata
Assignees
Labels
Issues related to the framework runtimeIssues related to the framework runtimeIssues related to Angular testing features, such as TestBedIssues related to Angular testing features, such as TestBed