Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

testing deferred components with timer with aot: true fails #61233

Copy link
Copy link
Open
@cexbrayat

Description

@cexbrayat
Issue body actions

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

No one assigned

    Labels

    area: coreIssues related to the framework runtimeIssues related to the framework runtimearea: testingIssues related to Angular testing features, such as TestBedIssues related to Angular testing features, such as TestBed

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.