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

Provide the ability to test directives that contain input signals without wrapper components #54164

Open
jamcoupe opened this issue Jan 30, 2024 · 2 comments
Labels
area: testing Issues related to Angular testing features, such as TestBed
Milestone

Comments

@jamcoupe
Copy link
Contributor

Which @angular/* package(s) are relevant/related to the feature request?

core

Description

Given the following simple directive with a signal input:

@Directive({
  selector: '[appSimple]',
  standalone: true,
  host: {
    '(click)': 'doSomething()',
  }
})
export class SimpleDirective {
  data = input.required<string>();

  doSomething() {
    console.log(this.data());
  }
}

There is no way for me to write a test because I can not use create a "DirectiveFixture"

Proposed solution

Provide a similar approach as TestBed.compileComponents but for directives.

Alternatives considered

Stick with requiring wrapper components to test, but add documentation when input signals become available as part of the public API.

@atscott atscott added the area: testing Issues related to Angular testing features, such as TestBed label Jan 30, 2024
@ngbot ngbot bot added this to the needsTriage milestone Jan 30, 2024
@jamcoupe
Copy link
Contributor Author

jamcoupe commented Feb 3, 2024

@topdev658 Your example is how I am currently testing signal directives.

This feature request was to not require wrapper component to test signal directives which is what your example does.

@JeanMeche
Copy link
Member

My take on this would be that, it doesn't really make sense to test a directive without a HostElement as it would not represent how they behave at runtime.

Depending on your test scenario, it could make sense to extract some logic from your directive into a separate class/function and test it separately.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: testing Issues related to Angular testing features, such as TestBed
Projects
None yet
Development

No branches or pull requests

4 participants
@atscott @JeanMeche @jamcoupe and others