Skip to content

Zoneless tests with unset required inputs succeeds unexpectedly #56977

Closed

Description

@szacskesz

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

core, zone.js

Is this a regression?

Yes

Description

I am testing a component with (signal based) required inputs. When no value is provided to the required input, it should throw an NG0950 error. With zone change detection it was the case, but when the provideExperimentalZonelessChangeDetection() is used, the tests succeeds unexpectedly.

After examining the logs I see the NG0950 error logged, but the test still succeeds.
I believe it might be related to #56240

Please provide a link to a minimal reproduction of the bug

https://stackblitz.com/edit/stackblitz-starters-pdwsvu?file=src%2Fapp%2Fapp.component.spec.ts

Please provide the exception or error you saw

> ng test

✔ Browser application bundle generation complete.
13 07 2024 15:41:47.999:WARN [karma]: No captured browser, open http://localhost:9876/
13 07 2024 15:41:48.010:INFO [karma-server]: Karma v6.4.3 server started at http://localhost:9876/
13 07 2024 15:41:48.010:INFO [launcher]: Launching browsers Chrome with concurrency unlimited
13 07 2024 15:41:48.012:INFO [launcher]: Starting browser Chrome
13 07 2024 15:41:48.525:INFO [Chrome 126.0.0.0 (Windows 10)]: Connected on socket PaQI-IqyyYwYYJJcAAAB with id 11717700
ERROR: 'ERROR', Error: NG0950: Input is required but no value is available yet. Find more at https://angular.dev/errors/NG0950
Error: NG0950: Input is required but no value is available yet. Find more at https://angular.dev/errors/NG0950
    at AppComponent.inputValueFn [as a2] (http://localhost:9876/_karma_webpack_/webpack:/node_modules/@angular/core/fesm2022/core.mjs:98:19)
    at templateFn (ng:///AppComponent.js:111:54)
    at executeTemplate (http://localhost:9876/_karma_webpack_/webpack:/node_modules/@angular/core/fesm2022/core.mjs:11620:9)
    at refreshView (http://localhost:9876/_karma_webpack_/webpack:/node_modules/@angular/core/fesm2022/core.mjs:13238:13)
    at detectChangesInView (http://localhost:9876/_karma_webpack_/webpack:/node_modules/@angular/core/fesm2022/core.mjs:13454:9)
    at detectChangesInViewIfAttached (http://localhost:9876/_karma_webpack_/webpack:/node_modules/@angular/core/fesm2022/core.mjs:13414:5)
    at detectChangesInComponent (http://localhost:9876/_karma_webpack_/webpack:/node_modules/@angular/core/fesm2022/core.mjs:13403:5)
    at detectChangesInChildComponents (http://localhost:9876/_karma_webpack_/webpack:/node_modules/@angular/core/fesm2022/core.mjs:13467:9)
    at refreshView (http://localhost:9876/_karma_webpack_/webpack:/node_modules/@angular/core/fesm2022/core.mjs:13292:13)
    at detectChangesInView (http://localhost:9876/_karma_webpack_/webpack:/node_modules/@angular/core/fesm2022/core.mjs:13454:9)
Chrome 126.0.0.0 (Windows 10): Executed 0 of 1 SUCCESS (0 secs / 0 secs)
ERROR: 'ERROR', Error: NG0950: Input is required but no value is available yet. Find more at https://angular.dev/errors/NG0950
Error: NG0950: Input is required but no value is available yet. Find more at https://angular.dev/errors/NG0950
    at AppComponent.inputValueFn [as a2] (http://localhost:9876/_karma_webpack_/webpack:/node_modules/@angular/core/fesm2022/core.mjs:98:19)
    at templateFn (ng:///AppComponent.js:111:54)
    at executeTemplate (http://localhost:9876/_karma_webpack_/webpack:/node_modules/@angular/core/fesm2022/core.mjs:11620:9)
    at refreshView (http://localhost:9876/_karma_webpack_/webpack:/node_modules/@angular/core/fesm2022/core.mjs:13238:13)
    at detectChangesInView (http://localhost:9876/_karma_webpack_/webpack:/node_modules/@angular/core/fesm2022/core.mjs:13454:9)
    at detectChangesInViewIfAttached (http://localhost:9876/_karma_webpack_/webpack:/node_modules/@angular/core/fesm2022/core.mjs:13414:5)
    at detectChangesInComponent (http://localhost:9876/_karma_webpack_/webpack:/node_modules/@angular/core/fesm2022/core.mjs:13403:5)
    at detectChangesInChildComponents (http://localhost:9876/_karma_webpack_/webpack:/node_modules/@angular/core/fesm2022/core.mjs:13467:9)
    at refreshView (http://localhost:9876/_karma_webpack_/webpack:/node_modules/@angular/core/fesm2022/core.mjs:13292:13)
Chrome 126.0.0.0 (Windows 10): Executed 1 of 1 SUCCESS (0.531 secs / 0.424 secs)
TOTAL: 1 SUCCESS

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

Angular CLI: 18.1.0
Node: 20.15.0
Package Manager: npm 10.7.0
OS: win32 x64

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

Package                         Version
---------------------------------------------------------
@angular-devkit/architect       0.1801.0
@angular-devkit/build-angular   18.1.0
@angular-devkit/core            18.1.0
@angular-devkit/schematics      18.1.0
@schematics/angular             18.1.0
rxjs                            7.8.1
typescript                      5.5.3
zone.js                         0.14.7

Anything else?

No response

Activity

  1. added
    area: testing
    core: zoneless
    on Jul 13, 2024
  2. modified the milestone: needsTriage on Jul 13, 2024
  3. JeanMeche commented on Jul 13, 2024

    @JeanMeche
    Member

    Take away a doubt from me, in the zone app, the error is thrown when you call fixture.detectChanges() right ?

  4. szacskesz commented on Jul 13, 2024

    @szacskesz
    Author

    Take away a doubt from me, in the zone app, the error is thrown when you call fixture.detectChanges() right ?

    Yes, see the same repro for the zone app:
    https://stackblitz.com/edit/stackblitz-starters-tp2ugc?file=src%2Fapp%2Fapp.component.spec.ts

  5. JeanMeche commented on Jul 13, 2024

    @JeanMeche
    Member

    So yeah basically this is same root cause than #56240.

    In the zone app, it's the detectChanges(), a function that is invoked in the test that fires the error.

    In the case of the zoneless test, the CD is fired from an ApplicationRef.tick which wraps everything in a try-catch block and logs the errors to the ErrorHandler.

    Testing in zoneless apps is a topic in itself that still need some work. You find some details here.

  6. added a commit that references this issue on Jul 29, 2024
    f7ab040
  7. added a commit that references this issue on Jul 29, 2024
    3a63c9e
  8. angular-automatic-lock-bot commented on Aug 29, 2024

    @angular-automatic-lock-bot

    This issue has been automatically locked due to inactivity.
    Please file a new issue if you are encountering a similar or related problem.

    Read more about our automatic conversation locking policy.

    This action has been performed automatically by a bot.

  9. locked and limited conversation to collaborators on Aug 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area: testingcore: zoneless

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions