angular / angular/components

table[mat-table] doesn't allow debugElement.query to find directives inside it

Open
#14,375 12 comments 29 reactions 0 assignees View on GitHub
area: material/table P4
Dominant language
TypeScript
Stars
25k
Forks
6.8k
Avg merge
1d 8h
Merged PRs (30d)
91

Description

#### Bug, feature request, or proposal:
Bug: `table[mat-table]` makes testing hard because it doesn't have a way for getting `debugElement`s to be queried.

#### What is the expected behavior?
`fixture.debugElement.query(By.css('*'))` should find directives inside a mat-table

#### What is the current behavior?
`fixture.debugElement.query(By.css('*'))` only finds `table[mat-table]` as a DebugElement but it can't find any other debug element that's a child of the table

#### What are the steps to reproduce?
https://stackblitz.com/edit/angular-testing-template-4n6yno
This has 2 describes: 1 with `table[mat-table]` (normal table) and another with `mat-table` (flex tables)

#### What is the use-case or motivation for changing an existing behavior?
Testing is hard otherwise, my work around has been overriding the module, remove the directive, make a fake directive that has `@HostBinding('click') click() { capturedInstance = this; }` and test with that.

#### Which versions of Angular, Material, OS, TypeScript, browsers are affected?
6.0.0

#### Is there anything else we should know?
As implicitly mentioned above, `` works OK, the problem seems to be on how `` renders the rows which seems to be with `createEmbeddedView`

Contributor guide

Open the contributing guide

Research direction

Start with the linked StackBlitz reproduction and compare the two describes for table[mat-table] and mat-table. Trace how the table renders rows through createEmbeddedView and verify whether fixture.debugElement.query(By.css('*')) can reach child elements. Done means the normal table exposes its child DebugElements while the existing mat-table case still works.

Written by the indexing model from the issue text.

Assessment

Tech stack
angular, typescript
Domain
frontend, testing
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.