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

Angular Component Testing: signal-based input aliasing not supported #29271

Closed
Waterstraal opened this issue Apr 5, 2024 · 1 comment
Closed
Labels
type: duplicate This issue or pull request already exists

Comments

@Waterstraal
Copy link

Waterstraal commented Apr 5, 2024

Current behavior

Signal-based inputs were introduced in Angular 17.1 and are not supported in Cypress. Issue #29264 addresses issues with types in componentProperties. This issue expands on that, as that Cypress also does not understand signal input aliasing.

It is possible to rename an input signal using the alias config option. See this example:

@Component({
  selector: 'app-input-alias-test-component',
  template: `{{ title() }}`,
  standalone: true,
  changeDetection: ChangeDetectionStrategy.OnPush,
})
class InputAliasTestComponent {
  title = input.required<string>({alias: 'superTitle'})
}

The Component now exposes a superTitle property instead of a title, of type string.

In Cypress component testing, the componentProperties incorrectly assumes a title property instead of superTitle:

Partial<{ title: InputSignal<string> }> | undefined

Note: The type of the title property is also wrong, it should be a string instead of an inputSignal<string>. But this is addressed in issue #29264.

Desired behavior

Cypress should understand signal inputs with an alias and reflect this in a correct componentProperties type.

Test code to reproduce

component-test.cy.ts:

@Component({
  selector: 'app-input-alias-test-component',
  template: `{{ title() }}`,
  standalone: true,
  changeDetection: ChangeDetectionStrategy.OnPush,
})
class InputAliasTestComponent {
  title = input.required<string>({alias: 'superTitle'})
}

it.only('mount component with component properties', () => {
  cy.mount(InputAliasTestComponent, {
    componentProperties: {
      superTitle: 'Test Component',
    },
  });
});

Cypress Version

13.7.2

Node version

20.10.0

Operating System

Win 11

Debug Logs

(uncaught exception)Error: NG0950: Input is required but no value is available yet. Find more at https://angular.io/errors/NG0950
(uncaught exception)Error: NG0950: Input is required but no value is available yet. Find more at https://angular.io/errors/NG0950
(uncaught exception)Error: NG0950: Input is required but no value is available yet. Find more at https://angular.io/errors/NG0950
(uncaught exception)Error: NG0950: Input is required but no value is available yet. Find more at https://angular.io/errors/NG0950
(uncaught exception)Error: NG0950: Input is required but no value is available yet. Find more at https://angular.io/errors/NG0950
(uncaught exception)Error: NG0950: Input is required but no value is available yet. Find more at https://angular.io/errors/NG0950
(uncaught exception)Error: NG0950: Input is required but no value is available yet. Find more at https://angular.io/errors/NG0950

Other

No response

@jennifer-shehane jennifer-shehane added type: feature New feature that does not currently exist npm: @cypress/angular @cypress/angular package issues CT Issue related to component testing labels Apr 12, 2024
@jennifer-shehane
Copy link
Member

Duplicate of #29264

@jennifer-shehane jennifer-shehane marked this as a duplicate of #29264 Apr 12, 2024
@jennifer-shehane jennifer-shehane closed this as not planned Won't fix, can't repro, duplicate, stale Apr 12, 2024
@jennifer-shehane jennifer-shehane added type: duplicate This issue or pull request already exists and removed type: feature New feature that does not currently exist npm: @cypress/angular @cypress/angular package issues CT Issue related to component testing labels Apr 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: duplicate This issue or pull request already exists
Projects
None yet
Development

No branches or pull requests

2 participants