Skip to content

Support on with render that receive an template #470

Open

Activity

edgargonzalez525

edgargonzalez525 commented on Sep 3, 2024

@edgargonzalez525

this issue is also present when using inputs not only outputs @timdeschryver

mumenthalers

mumenthalers commented on Sep 4, 2024

@mumenthalers

When providing a template rather than a component type, the WrapperComponent is used with it's template part overwritten.

@timdeschryver I don't think it would be useful to support on and inputs for templates.
The main task for them is to subscribe to existing observables , and to provide values to existing inputs while providing supportive types.

I'd propose to only work with componentProperties when using a template as this already works perfectly for this case . Maybe the signature could be changed accordingly (to only support componentProperties when providing a template)
afaik there is no other way to achieve this binding than to write component properties of the WrapperComponent.

--> imo the componentProperties should definitely not be deprecated

  it('template test', async () => {
    @Component({standalone: true, template:`<button (click)="event.emit()">{{value()}}</button>`, selector: 'app-test'})
    class AppTestComponent {
      readonly value = input.required<string>()
      readonly event = output<void>()
    }
    const value = 'foo bar'
    const fn = jest.fn()
    const result = await render(
      '<app-test [value]="value" (event)="fn($event)"/>',
      {
        imports: [AppTestComponent],
        componentProperties: { value, fn }
      }
    )
    const button = result.getByRole('button')
    expect(button).toHaveTextContent(value)
    button.click()
    expect(fn).toHaveBeenCalled()
  })
timdeschryver

timdeschryver commented on Sep 4, 2024

@timdeschryver
MemberAuthor

@mumenthalers that's a valid point, and something I was also thinking.
This is something we can do for the next major release.
Thanks for your input, it's appreciated!

linked a pull request that will close this issue on Mar 21, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Participants

      @mumenthalers@edgargonzalez525@timdeschryver

      Issue actions

        Support `on` with `render` that receive an template · Issue #470 · testing-library/angular-testing-library