components icon indicating copy to clipboard operation
components copied to clipboard

Lazily loaded menu content with ngIf not showing in testbed

Open hags033 opened this issue 6 years ago • 4 comments

Reproduction

Steps to reproduce:

  1. have a lazily loaded mat menu (ng-content>matMenuContent), with mat-menu-items and non mat-menu-items inside with *ngIf(s) on them
  2. Use the MatMenuHarness to find and open your mat menu in a unit test
  3. use getItems() to locate the mat-menu-items
  4. use css.queries to find non mat-menu-items

This started happening as of material, cdk, cdk experimental 10.1.2

Expected Behavior

I would expect to be able to query non mat-menu-item(s) with css, using the harness to open lazily loaded mat menu content area.

Harness getItems() will find the menu item if ngIf is true and won't find if false, which works as expected.

Actual Behavior

You can query and find non mat-menu-items in the test only if they do not have an ngIf on them. You cannot query and find non mat-menu-items if they have an ngIf on them regardless if the ngIf is true or false.

Environment

  • Angular: 10.0.8
  • CDK/Material: 10.1.3
  • Browser(s):
  • Operating System (e.g. Windows, macOS, Ubuntu): macOS

hags033 avatar Aug 12 '20 19:08 hags033

Can you post what the template of the test component looks like?

crisbeto avatar Aug 13 '20 04:08 crisbeto

<button [matMenuTriggerFor]="subMenu">Click Me</button>
<mat-menu #subMenu="matMenu">
  <ng-template matMenuContent>
    <div mat-menu-item>item 1</div> <!-- found with harness after harness opens menu -->
    <div class="not-menu-item" >item 2</div> <!-- found with css query after opening with harness -->
    <div mat-menu-item *ngIf="true">item 3</div><!-- found with harness after harness opens menu -->
    <div class="not-menu-item" *ngIf="true">item 4</div><!-- not found with css query after opening with harness -->
  </ng-template>
</mat-menu>

hags033 avatar Aug 13 '20 15:08 hags033

We are closing this issue, because we've determined, using a semi-automated process, that it is no longer relevant, has low engagement, or it does not have enough information to proceed. Feel free to comment if you think the issue should be reopened, or open a new issue with the latest version of our code instead.

crisbeto avatar May 29 '26 12:05 crisbeto

This issue has been automatically locked due to inactivity. Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.