Skip to content

HarnessPredicate doesn't correctly apply ancestor selectors to compound component selectors  #22475

Closed
@jelbourn

Description

@jelbourn

Note(@jelbourn): Copied from an internal bug report

HarnessPredicate.getSelector returns the wrong result in certain cases. E.g., MatButtonHarness and other CDK harnesses are defined as matching one of several possible selectors:

  static hostSelector = [
    '[mat-button]',
    '[mat-raised-button]',
    '[mat-flat-button]',
    '[mat-icon-button]',
    '[mat-stroked-button]',
    '[mat-fab]',
    '[mat-mini-fab]',
  ].join(',');

I would expect getHarness(MatButtonHarness.with({ancestor: '.foo'})) to always find a MatButton that has a '.foo' ancestor. However, the current implementation of https://source.corp.google.com/search?q=HarnessPredicate.getSelector returns:

.foo [mat-button],[mat-raised-button],[mat-flat-button],[mat-icon-button],[mat-stroked-button],[mat-fab],[mat-mini-fab]

which only applies the ancestor constraint to the first possibility.

Metadata

Metadata

Assignees

Labels

GThis is is related to a Google internal issueP2The issue is important to a large percentage of users, with a workaroundarea: cdk/testinghelp wantedThe team would appreciate a PR from the community to address this issue

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions