@@ -48,12 +48,36 @@ describe('MenuTrigger', () => {
4848 expect ( menuItemElement . getAttribute ( 'aria-disabled' ) ) . toBe ( 'true' ) ;
4949 } ) ;
5050
51- it ( 'should set aria-haspopup to menu' , ( ) => {
51+ it ( 'should set aria-haspopup based on whether a menu is assigned ' , ( ) => {
5252 expect ( menuItemElement . getAttribute ( 'aria-haspopup' ) ) . toEqual ( 'menu' ) ;
53+
54+ fixture . componentInstance . trigger . menuTemplateRef = null ;
55+ fixture . detectChanges ( ) ;
56+
57+ expect ( menuItemElement . hasAttribute ( 'aria-haspopup' ) ) . toBe ( false ) ;
5358 } ) ;
5459
55- it ( 'should have a menu' , ( ) => {
60+ it ( 'should have a menu based on whether a menu is assigned ' , ( ) => {
5661 expect ( menuItem . hasMenu ) . toBeTrue ( ) ;
62+
63+ fixture . componentInstance . trigger . menuTemplateRef = null ;
64+ fixture . detectChanges ( ) ;
65+
66+ expect ( menuItem . hasMenu ) . toBeFalse ( ) ;
67+ } ) ;
68+
69+ it ( 'should set aria-controls based on whether a menu is assigned' , ( ) => {
70+ expect ( menuItemElement . hasAttribute ( 'aria-controls' ) ) . toBeFalse ( ) ;
71+ } ) ;
72+
73+ it ( 'should set aria-expanded based on whether a menu is assigned' , ( ) => {
74+ expect ( menuItemElement . hasAttribute ( 'aria-expanded' ) ) . toBeTrue ( ) ;
75+ expect ( menuItemElement . getAttribute ( 'aria-expanded' ) ) . toBe ( 'false' ) ;
76+
77+ fixture . componentInstance . trigger . menuTemplateRef = null ;
78+ fixture . detectChanges ( ) ;
79+
80+ expect ( menuItemElement . hasAttribute ( 'aria-expanded' ) ) . toBeFalse ( ) ;
5781 } ) ;
5882 } ) ;
5983
@@ -471,21 +495,10 @@ describe('MenuTrigger', () => {
471495 expect ( document . querySelector ( '.test-menu' ) ?. textContent ) . toBe ( 'Hello!' ) ;
472496 } ) ;
473497
474- describe ( 'null triggerFor' , ( ) => {
498+ xdescribe ( 'null triggerFor' , ( ) => {
475499 let fixture : ComponentFixture < TriggerWithNullValue > ;
476500
477501 let nativeTrigger : HTMLElement ;
478- let contextNativeTrigger : HTMLElement ;
479-
480- const grabElementsForTesting = ( ) => {
481- nativeTrigger = fixture . componentInstance . nativeTrigger . nativeElement ;
482- } ;
483-
484- /** run change detection and, extract and set the rendered elements */
485- const detectChanges = ( ) => {
486- fixture . detectChanges ( ) ;
487- grabElementsForTesting ( ) ;
488- } ;
489502
490503 beforeEach ( waitForAsync ( ( ) => {
491504 TestBed . configureTestingModule ( {
@@ -496,7 +509,7 @@ describe('MenuTrigger', () => {
496509
497510 beforeEach ( ( ) => {
498511 fixture = TestBed . createComponent ( TriggerWithNullValue ) ;
499- detectChanges ( ) ;
512+ nativeTrigger = fixture . componentInstance . nativeTrigger . nativeElement
500513 } ) ;
501514
502515 it ( 'should not set aria-haspopup' , ( ) => {
@@ -511,15 +524,17 @@ describe('MenuTrigger', () => {
511524 expect ( fixture . componentInstance . trigger . isOpen ( ) ) . toBeFalse ( ) ;
512525
513526 nativeTrigger . click ( ) ;
514- detectChanges ( ) ;
527+ fixture . detectChanges ( ) ;
528+
515529 expect ( fixture . componentInstance . trigger . isOpen ( ) ) . toBeFalse ( ) ;
516530 } ) ;
517531
518532 it ( 'should not toggle the menu on keyboard events' , ( ) => {
519533 expect ( fixture . componentInstance . trigger . isOpen ( ) ) . toBeFalse ( ) ;
520534
521535 dispatchKeyboardEvent ( nativeTrigger , 'keydown' , SPACE ) ;
522- detectChanges ( ) ;
536+ fixture . detectChanges ( ) ;
537+
523538 expect ( fixture . componentInstance . trigger . isOpen ( ) ) . toBeFalse ( ) ;
524539 } ) ;
525540 } ) ;
@@ -531,7 +546,10 @@ describe('MenuTrigger', () => {
531546 <ng-template #noop><div cdkMenu></div></ng-template>
532547 ` ,
533548} )
534- class TriggerForEmptyMenu { }
549+ class TriggerForEmptyMenu {
550+ @ViewChild ( CdkMenuTrigger ) trigger : CdkMenuTrigger ;
551+ @ViewChild ( CdkMenuTrigger , { read : ElementRef } ) nativeTrigger : ElementRef ;
552+ }
535553
536554@Component ( {
537555 template : `
0 commit comments