Skip to content

Commit

Permalink
fix: unit test failures
Browse files Browse the repository at this point in the history
  • Loading branch information
crisbeto committed Feb 19, 2017
1 parent 47a0f72 commit 3193bcd
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions src/lib/autocomplete/autocomplete.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,12 +87,12 @@ describe('MdAutocomplete', () => {
.toContain('California', `Expected panel to display when opened programmatically.`);
});

it('should close the panel when blurred', async(() => {
it('should close the panel when input loses focus', async(() => {
dispatchEvent('focus', input);
fixture.detectChanges();

fixture.whenStable().then(() => {
dispatchEvent('focusout', input);
dispatchEvent('focusout', input, { relatedTarget: document.body });
fixture.detectChanges();

expect(fixture.componentInstance.trigger.panelOpen)
Expand Down Expand Up @@ -413,7 +413,7 @@ describe('MdAutocomplete', () => {
.toBe(false, `Expected control to stay pristine if value is set programmatically.`);
});

it('should mark the autocomplete control as touched on blur', () => {
it('should mark the autocomplete control as touched on focusout', () => {
fixture.componentInstance.trigger.openPanel();
fixture.detectChanges();
expect(fixture.componentInstance.stateCtrl.touched)
Expand All @@ -423,7 +423,7 @@ describe('MdAutocomplete', () => {
fixture.detectChanges();

expect(fixture.componentInstance.stateCtrl.touched)
.toBe(true, `Expected control to become touched on blur.`);
.toBe(true, `Expected control to become touched on focusout.`);
});

});
Expand Down Expand Up @@ -913,9 +913,15 @@ class AutocompleteWithoutForms {
* Dispatches an event from an element.
* @param eventName Name of the event
* @param element The element from which the event will be dispatched.
* @param extras Extra properties to be attached to the event object.
*/
function dispatchEvent(eventName: string, element: HTMLElement): void {
function dispatchEvent(eventName: string, element: HTMLElement, extras?: any): void {
let event = document.createEvent('Event');

if (extras) {
Object.assign(event, extras);
}

event.initEvent(eventName, true, true);
element.dispatchEvent(event);
}
Expand Down

0 comments on commit 3193bcd

Please sign in to comment.