Skip to content

Component with attribute selector #263

@mleimer

Description

@mleimer
Contributor

Problem

Based on the examples https://github.com/testing-library/angular-testing-library/blob/main/apps/example-app/src/app/examples/02-input-output.ts and https://github.com/testing-library/angular-testing-library/blob/main/apps/example-app/src/app/examples/02-input-output.spec.ts

Given that a component contains an attribute within its selector
e.g. app-fixture[value]

Then it is not possible to render the component with:
await render(InputOutputComponent, { componentProperties: { value: 47, sendValue: { emit: sendValue, } as any, }, });

Instead, the template way must be chosen:
await render('<app-fixture [value]="47" (sendValue)="sendValue($event)" (clicked)="clicked()"></app-fixture>', { declarations: ['InputOutputComponent'], componentProperties: { sendValue: sendSpy, }, });

Suggestion

  • Add documentation that the regular render does not work with attribute components OR if there is a way to make it work, enhance the code base
  • Update the example, as it uses a deprecated render-method where the template is passed as a property in the second argument instead of the first argument.

Activity

timdeschryver

timdeschryver commented on Nov 24, 2021

@timdeschryver
Member

Thanks for creating this issue @mleimer .
This is the first time that this use case pops up, and I don't think there's something that we can provide to fix this for now - but I'll think on it a while longer. For now, adding a note in the docs is the best way to go.

Updating the example is also a good point that you bring up.

Do you want to create a PR for one/both of these suggestions?

mleimer

mleimer commented on Nov 26, 2021

@mleimer
ContributorAuthor

I created a PR at #264

  • It updates existing examples by using the new render-method to render templates
  • It adds a new example and a note how to render components with an attribute selector
  • It does not provide a solution how to handle components with an attribute selector without using a template
added a commit that references this issue on Nov 26, 2021
224e550
timdeschryver

timdeschryver commented on Nov 26, 2021

@timdeschryver
Member

Thanks for your help @mleimer

github-actions

github-actions commented on Nov 26, 2021

@github-actions

🎉 This issue has been resolved in version 11.0.0-beta.3 🎉

The release is available on:

Your semantic-release bot 📦🚀

added a commit that references this issue on Dec 3, 2021
eb06c83
github-actions

github-actions commented on Dec 3, 2021

@github-actions

🎉 This issue has been resolved in version 11.0.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @mleimer@timdeschryver

        Issue actions

          Component with attribute selector · Issue #263 · testing-library/angular-testing-library