Skip to content

Commit b028856

Browse files
committed
fix: unit test failures
1 parent cbb5f49 commit b028856

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)
@@ -417,7 +417,7 @@ describe('MdAutocomplete', () => {
417417
.toBe(false, `Expected control to stay pristine if value is set programmatically.`);
418418
});
419419

420-
it('should mark the autocomplete control as touched on blur', () => {
420+
it('should mark the autocomplete control as touched on focusout', () => {
421421
fixture.componentInstance.trigger.openPanel();
422422
fixture.detectChanges();
423423
expect(fixture.componentInstance.stateCtrl.touched)
@@ -427,7 +427,7 @@ describe('MdAutocomplete', () => {
427427
fixture.detectChanges();
428428

429429
expect(fixture.componentInstance.stateCtrl.touched)
430-
.toBe(true, `Expected control to become touched on blur.`);
430+
.toBe(true, `Expected control to become touched on focusout.`);
431431
});
432432

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

0 commit comments

Comments
 (0)