Skip to content

How to set hostDirective inputs in tests ? #512

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

Closed
CorentinGROSDEMOUGE opened this issue Jan 9, 2025 · 2 comments
Closed

How to set hostDirective inputs in tests ? #512

CorentinGROSDEMOUGE opened this issue Jan 9, 2025 · 2 comments

Comments

@CorentinGROSDEMOUGE
Copy link

I have a component that have two hostDirectives, which has required inputs.
How can i add these inputs without using a custom type on the inputs property from render function ?

@timdeschryver
Copy link
Member

timdeschryver commented Jan 10, 2025

It looks like #514.
There is not a "real" API for this, but you can just define it as an input.
Sadly, it cannot be typed as far as I know.

@CorentinGROSDEMOUGE
Copy link
Author

CorentinGROSDEMOUGE commented Jan 13, 2025

That's what i'm doing for the moment.

It's a bit ugly but i declare a type and performs a type assertion on the input property. Ugly but working 😅

type MyComponentInputs =
  ComponentInput<T
    & { automatedTestAnchor: AutomatedTestAnchorDirective['designSystemAutomatedTestAnchor'] }
  >
  
  // ...
  
  // Dumb test
  it('should instantiate', async () => {
      const { fixture } = await render(MyComponentInputs , {
        inputs: {
          text: 'Title',
          automatedTestAnchor: 'foobar'
        } satisfies MyComponentInputs as MyComponentInputs,
      });

      expect(fixture.componentInstance).toBeInstanceOf(LinkCardComponent);
    });

Thanks for the answer, i'll subscribe to the other issue too.

Edit : If i can use aliasedInput it will be way better !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants