Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: Input signals in components cause tests to error out (Angular v17.1.0) #2246

Closed
gpremo-re opened this issue Jan 22, 2024 · 8 comments · Fixed by #2303
Closed

[Bug]: Input signals in components cause tests to error out (Angular v17.1.0) #2246

gpremo-re opened this issue Jan 22, 2024 · 8 comments · Fixed by #2303
Labels
🐛 Bug Confirmed Bug is confirmed

Comments

@gpremo-re
Copy link

gpremo-re commented Jan 22, 2024

Version

14.0.0

Steps to reproduce

  1. Clone my repo (forked from this repo) https://github.com/gpremo-re/jest-preset-angular
  2. Run tests in example-app-v17 (specifically DashboardHeroComponent)

Expected behavior

I expect unit tests to succeed when using input() signals in a component.

Actual behavior

All tests fail.

For example:
DashboardHeroComponent when inside a test host fails with the following errors

  console.error
    NG0303: Can't bind to 'hero' since it isn't a known property of 'dashboard-hero' (used in the 'TestHostComponent' component template).
    1. If 'dashboard-hero' is an Angular component and it has the 'hero' input, then verify that it is included in the '@Component.imports' of this component.
    2. If 'dashboard-hero' is a Web Component then add 'CUSTOM_ELEMENTS_SCHEMA' to the '@Component.schemas' of this component to suppress this message.
    3. To allow any property add 'NO_ERRORS_SCHEMA' to the '@Component.schemas' of this component.

      at reportUnknownPropertyError (node_modules/@angular/core/fesm2022/core.mjs:7418:17)
      at TestHostComponent_Template (ng:/TestHostComponent.js:14:21)
      at src/app/dashboard/dashboard-hero.component.spec.ts:100:13
Error: NG0950: Input is required but no value is available yet. Find more at https://angular.io/errors/NG0950

    at DashboardHeroComponent.inputValueFn [as hero] (C:\Projects\jest-preset-angular\examples\example-app-v17\node_modules\@angular\core\fesm2022\core.mjs:98:19)
    at DashboardHeroComponent_Template (ng:///DashboardHeroComponent.js:19:65)
    at executeTemplate (C:\Projects\jest-preset-angular\examples\example-app-v17\node_modules\@angular\core\fesm2022\core.mjs:12263:9)
    at refreshView (C:\Projects\jest-preset-angular\examples\example-app-v17\node_modules\@angular\core\fesm2022\core.mjs:13490:13)
    ...
    at NgZone.run (C:\Projects\jest-preset-angular\examples\example-app-v17\node_modules\@angular\core\fesm2022\core.mjs:14632:28)
    at ComponentFixture.detectChanges (C:\Projects\jest-preset-angular\examples\example-app-v17\node_modules\@angular\core\fesm2022\testing.mjs:251:22)
    at C:\Projects\jest-preset-angular\examples\example-app-v17\src\app\dashboard\dashboard-hero.component.spec.ts:100:13

`

Additional context

The diff between my local branch and the mainline branch: main...gpremo-re:jest-preset-angular:main

Environment

System:
    OS: Windows 11 10.0.22631
    CPU: (24) x64 AMD Ryzen 9 5900X 12-Core Processor
  Binaries:
    Node: 20.9.0 - ~\scoop\apps\nodejs-lts\current\node.EXE
    Yarn: 3.7.0 - ~\scoop\apps\nodejs-lts\current\bin\yarn.CMD
    npm: 10.1.0 - ~\scoop\apps\nodejs-lts\current\bin\npm.CMD
    pnpm: 8.10.2 - ~\scoop\apps\nodejs-lts\current\bin\pnpm.CMD
@ahnpnl
Copy link
Collaborator

ahnpnl commented Jan 23, 2024

I already had a chat with Angular team about this, an extra AST transformation is needed. WIP to adopt it

@gpremo-re
Copy link
Author

@ahnpnl Love to see you guys are so on top of it! I was wondering what the status of this was, and if you're looking for any additional help. I'd be happy to spearhead this specific issue if the core contributors have higher priorities.

@ahnpnl
Copy link
Collaborator

ahnpnl commented Jan 30, 2024

I just opened a PR. We are trying to use esbuild bundle mode to remove the effort of manually downloading angular source but let esbuild take care of it and build everything.

@bhalperin
Copy link

I'm also waiting for a fix. Thanks.

@Nesho-Developer
Copy link

when will the PR be merged?

@vikashkumar29
Copy link

vikashkumar29 commented Mar 11, 2024

We are using nx monorepo where we are still seeing the same issue. We tried the latest version but could not get through. We are using the following versions:

angular: 17.1.0
nx: 18.0.8
jest: 29.7.0
jest-preset-angular: 14.0.3

Any help on this would be really helpful.

@PowerSupply
Copy link

I would like to add that this is also a problem when dynamically creating a component through using createComponent.

This is really a problem since it prevents us from creating any component that has a signal input. The problem gets even bigger since there is no way of knowing if any inputs are required or not. The ComponentMirror interface is missing that information.

@vbraun
Copy link

vbraun commented Apr 5, 2024

With 14.0.3 I can set normal input signals, but input.required signals fail. I've opened #2370

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🐛 Bug Confirmed Bug is confirmed
Projects
None yet
7 participants