@@ -30,7 +30,6 @@ import {
30
30
} from '@angular/core' ;
31
31
import { ComponentFixture , fakeAsync , flush , TestBed , tick } from '@angular/core/testing' ;
32
32
import { By } from '@angular/platform-browser' ;
33
- import { NoopAnimationsModule } from '@angular/platform-browser/animations' ;
34
33
import { Subject } from 'rxjs' ;
35
34
import {
36
35
createKeyboardEvent ,
@@ -256,10 +255,6 @@ describe('MatMenu', () => {
256
255
} ) ) ;
257
256
258
257
it ( 'should move focus to another item if the active item is destroyed' , fakeAsync ( ( ) => {
259
- // TODO(crisbeto): figure out why NoopAnimationsModule is necessary
260
- // here and our token isn't enough. Likely indicates an issue.
261
- TestBed . resetTestingModule ( ) . configureTestingModule ( { imports : [ NoopAnimationsModule ] } ) ;
262
- overlayContainerElement = TestBed . inject ( OverlayContainer ) . getContainerElement ( ) ;
263
258
const fixture = TestBed . createComponent ( MenuWithRepeatedItems ) ;
264
259
fixture . detectChanges ( ) ;
265
260
const triggerEl = fixture . componentInstance . triggerEl . nativeElement ;
@@ -268,17 +263,19 @@ describe('MatMenu', () => {
268
263
fixture . detectChanges ( ) ;
269
264
tick ( 500 ) ;
270
265
271
- const items = overlayContainerElement . querySelectorAll (
266
+ const items = overlayContainerElement . querySelectorAll < HTMLElement > (
272
267
'.mat-mdc-menu-panel .mat-mdc-menu-item' ,
273
268
) ;
274
269
275
- expect ( document . activeElement ) . toBe ( items [ 0 ] ) ;
270
+ // Stub out the `_hasFocus` method since it's hard to move focus reliably within the test.
271
+ spyOn ( fixture . componentInstance . itemInstances . first , '_hasFocus' ) . and . callFake ( ( ) => true ) ;
272
+ const spy = spyOn ( items [ 1 ] , 'focus' ) ;
276
273
277
274
fixture . componentInstance . items . shift ( ) ;
278
275
fixture . detectChanges ( ) ;
279
276
tick ( 500 ) ;
280
277
281
- expect ( document . activeElement ) . toBe ( items [ 1 ] ) ;
278
+ expect ( spy ) . toHaveBeenCalled ( ) ;
282
279
} ) ) ;
283
280
284
281
it ( 'should be able to set a custom class on the backdrop' , fakeAsync ( ( ) => {
@@ -3027,5 +3024,6 @@ class MenuWithRepeatedItems {
3027
3024
@ViewChild ( MatMenuTrigger , { static : false } ) trigger : MatMenuTrigger ;
3028
3025
@ViewChild ( 'triggerEl' , { static : false } ) triggerEl : ElementRef < HTMLElement > ;
3029
3026
@ViewChild ( MatMenu , { static : false } ) menu : MatMenu ;
3027
+ @ViewChildren ( MatMenuItem ) itemInstances : QueryList < MatMenuItem > ;
3030
3028
items = [ 'One' , 'Two' , 'Three' ] ;
3031
3029
}
0 commit comments