Skip to content

ComponentFixture.whenStable doesn't detect event emitted from async output in zoneless CD #56290

@jnizet

Description

@jnizet

Which @angular/* package(s) are the source of the bug?

core

Is this a regression?

No

Description

In zoneless mode (i.e. with provideExperimentalZonelessChangeDetection()), a test using autoDetectChanges does not detect the changes caused by the emission of an event by a child output using an async EventEmitter (i.e. new EventEmitter(true)).

To make things clearer, use the minimal reproduction (see below), and execute the following commands in the terminal:

  • cd app
  • npm install
  • ng serve

Note at this point that clicking the two buttons works as expected: the associated "hello" message becomes "world".

Now run ng test.

The test for the "Async" section fails. The difference between the first and the second section is that the first one reacts to a sync output from the child component, whereas the second one reacts to an async output.

Using async outputs might seem weird (BTW, this option deoesn't exist with the new output() function), but this issue comes from a real use-case where it is actually used (ng-bootstrap's pagination component).

Please provide a link to a minimal reproduction of the bug

https://stackblitz.com/edit/stackblitz-starters-c2ydkj?file=app%2Fsrc%2Fapp%2Fapp.component.spec.ts

Please provide the exception or error you saw

No response

Please provide the environment you discovered this bug in (run ng version)

Angular CLI: 18.0.2
Node: 18.20.3
Package Manager: npm 10.2.3
OS: linux x64

Angular: 18.0.1
... animations, common, compiler, compiler-cli, core, forms
... platform-browser, platform-browser-dynamic, router

Package                         Version
---------------------------------------------------------
@angular-devkit/architect       0.1800.2
@angular-devkit/build-angular   18.0.2
@angular-devkit/core            18.0.2
@angular-devkit/schematics      18.0.2
@angular/cli                    18.0.2
@schematics/angular             18.0.2
rxjs                            7.8.1
typescript                      5.4.5
zone.js                         0.14.6

Anything else?

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    area: testingIssues related to Angular testing features, such as TestBedcore: zonelessIssues related to running Angular without zone.js

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions