Skip to content

Commit b34b440

Browse files
crisbetoandrewseguin
authored andcommitted
test(menu): fix test failures against Angular 4.2 (#5168)
Fixes a couple of menu unit tests that were failing against Angular 4.2.2.
1 parent 40072a1 commit b34b440

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

src/lib/menu/menu.spec.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {TestBed, async, ComponentFixture} from '@angular/core/testing';
1+
import {TestBed, async, ComponentFixture, fakeAsync, tick} from '@angular/core/testing';
22
import {By} from '@angular/platform-browser';
33
import {NoopAnimationsModule} from '@angular/platform-browser/animations';
44
import {
@@ -83,29 +83,31 @@ describe('MdMenu', () => {
8383
}).not.toThrowError();
8484
});
8585

86-
it('should close the menu when a click occurs outside the menu', () => {
86+
it('should close the menu when a click occurs outside the menu', fakeAsync(() => {
8787
const fixture = TestBed.createComponent(SimpleMenu);
8888
fixture.detectChanges();
8989
fixture.componentInstance.trigger.openMenu();
9090

9191
const backdrop = <HTMLElement>overlayContainerElement.querySelector('.cdk-overlay-backdrop');
9292
backdrop.click();
9393
fixture.detectChanges();
94+
tick(500);
9495

9596
expect(overlayContainerElement.textContent).toBe('');
96-
});
97+
}));
9798

98-
it('should close the menu when pressing escape', () => {
99+
it('should close the menu when pressing escape', fakeAsync(() => {
99100
const fixture = TestBed.createComponent(SimpleMenu);
100101
fixture.detectChanges();
101102
fixture.componentInstance.trigger.openMenu();
102103

103104
const panel = overlayContainerElement.querySelector('.mat-menu-panel')!;
104105
dispatchKeyboardEvent(panel, 'keydown', ESCAPE);
105106
fixture.detectChanges();
107+
tick(500);
106108

107109
expect(overlayContainerElement.textContent).toBe('');
108-
});
110+
}));
109111

110112
it('should open a custom menu', () => {
111113
const fixture = TestBed.createComponent(CustomMenu);

0 commit comments

Comments
 (0)