Skip to content

test(menu): fix test failures against Angular 4.2 #5168

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 27, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions src/lib/menu/menu.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {TestBed, async, ComponentFixture} from '@angular/core/testing';
import {TestBed, async, ComponentFixture, fakeAsync, tick} from '@angular/core/testing';
import {By} from '@angular/platform-browser';
import {NoopAnimationsModule} from '@angular/platform-browser/animations';
import {
Expand Down Expand Up @@ -70,29 +70,31 @@ describe('MdMenu', () => {
}).not.toThrowError();
});

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

const backdrop = <HTMLElement>overlayContainerElement.querySelector('.cdk-overlay-backdrop');
backdrop.click();
fixture.detectChanges();
tick(500);

expect(overlayContainerElement.textContent).toBe('');
});
}));

it('should close the menu when pressing escape', () => {
it('should close the menu when pressing escape', fakeAsync(() => {
const fixture = TestBed.createComponent(SimpleMenu);
fixture.detectChanges();
fixture.componentInstance.trigger.openMenu();

const panel = overlayContainerElement.querySelector('.mat-menu-panel');
dispatchKeyboardEvent(panel, 'keydown', ESCAPE);
fixture.detectChanges();
tick(500);

expect(overlayContainerElement.textContent).toBe('');
});
}));

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