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

refactor: stronger typing of inputs #473

Merged
merged 11 commits into from
Aug 3, 2024

Conversation

andreialecu
Copy link
Contributor

@andreialecu andreialecu commented Jul 29, 2024

Fixes #464

This PR restores the type safety of inputs and introduces a new property called inputs and deprecates componentInputs. Previously we had an union with { [alias: string]: unknown } which would essentially act as any.

We add a branded type through which aliases can be explicitly supplied.

Usage:

  @Component({
    selector: 'atl-fixture',
    template: `<span>{{ myName() }}</span> <span>{{ myJob() }}</span>`,
  })
  class InputComponent {
    myName = input('foo');

    myJob = input('bar', { alias: 'job' });
  }

  it('should set the input component', async () => {
    await render(InputComponent, {
      inputs: {
        myName: 'Bob',
        ...aliasedInput('job', 'Builder'),
      },
    });

    expect(screen.getByText('Bob')).toBeInTheDocument();
    expect(screen.getByText('Builder')).toBeInTheDocument();
  });

Copy link
Member

@timdeschryver timdeschryver left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your time and great work on this @andreialecu !

@timdeschryver timdeschryver merged commit 3095737 into testing-library:main Aug 3, 2024
4 checks passed
@timdeschryver
Copy link
Member

@all-contributors please add @andreialecu for code, ideas, doc

Copy link
Contributor

@timdeschryver

I've put up a pull request to add @andreialecu! 🎉

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

Successfully merging this pull request may close these issues.

signal-based inputs and componentInputs type
2 participants