question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Component with attribute selector

See original GitHub issue

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.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
mleimercommented, Nov 26, 2021

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
0reactions
github-actions[bot]commented, Dec 3, 2021

🎉 This issue has been resolved in version 11.0.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

Read more comments on GitHub >

github_iconTop Results From Across the Web

When to use an attribute selector for Angular components
A CSS element selector is by far the most popular way to mark an Angular component. Although, an attribute selector is mainly meant...
Read more >
Attribute selectors - CSS: Cascading Style Sheets | MDN
The CSS attribute selector matches elements based on the presence or value of a given attribute.
Read more >
Can an angular 2 component be used with an attribute selector?
Yes, the selector property of the @Component decorator is a CSS selector (or a subset of):. selector : '.cool-button:not(a)'. Specifies a CSS selector...
Read more >
Understanding the Purpose and Use of the Selector in Angular
A selector is one of the properties of the object that we use along with the component configuration. A selector is used to...
Read more >
Attribute directives - Angular
... or behavior of DOM elements and Angular components with attribute directives. ... specifies the directive's CSS attribute selector, [appHighlight] .
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found