Skip to content

Commit 3193bcd

Browse files
committed
fix: unit test failures
1 parent 47a0f72 commit 3193bcd

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

src/lib/autocomplete/autocomplete.spec.ts

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -87,12 +87,12 @@ describe('MdAutocomplete', () => {
8787
.toContain('California', `Expected panel to display when opened programmatically.`);
8888
});
8989

90-
it('should close the panel when blurred', async(() => {
90+
it('should close the panel when input loses focus', async(() => {
9191
dispatchEvent('focus', input);
9292
fixture.detectChanges();
9393

9494
fixture.whenStable().then(() => {
95-
dispatchEvent('focusout', input);
95+
dispatchEvent('focusout', input, { relatedTarget: document.body });
9696
fixture.detectChanges();
9797

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

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

425425
expect(fixture.componentInstance.stateCtrl.touched)
426-
.toBe(true, `Expected control to become touched on blur.`);
426+
.toBe(true, `Expected control to become touched on focusout.`);
427427
});
428428

429429
});
@@ -913,9 +913,15 @@ class AutocompleteWithoutForms {
913913
* Dispatches an event from an element.
914914
* @param eventName Name of the event
915915
* @param element The element from which the event will be dispatched.
916+
* @param extras Extra properties to be attached to the event object.
916917
*/
917-
function dispatchEvent(eventName: string, element: HTMLElement): void {
918+
function dispatchEvent(eventName: string, element: HTMLElement, extras?: any): void {
918919
let event = document.createEvent('Event');
920+
921+
if (extras) {
922+
Object.assign(event, extras);
923+
}
924+
919925
event.initEvent(eventName, true, true);
920926
element.dispatchEvent(event);
921927
}

0 commit comments

Comments
 (0)