Skip to content
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

fix(typeahead): fix error on blur after init #5760

Merged
Show file tree
Hide file tree
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
15 changes: 14 additions & 1 deletion src/spec/typeahead.directive.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* tslint:disable:max-file-line-count */
/* tslint:disable:no-floating-promises max-file-line-count */
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
import { By } from '@angular/platform-browser';
import { Component, DebugElement } from '@angular/core';
Expand Down Expand Up @@ -185,6 +185,19 @@ describe('Directive: Typeahead', () => {
expect(fixture.debugElement.query(By.css('typeahead-container'))).toBeNull();
})
);

it('should not throw an error on blur', fakeAsync(() => {
expect(directive._container).toBeFalsy();
expect(directive.matches).toEqual([]);

dispatchMouseEvent(inputElement, 'click');
tick();
fixture.detectChanges();

fixture.whenStable().then(() => {
expect(() => directive.onBlur()).not.toThrowError();
});
}));
});

describe('onFocus', () => {
Expand Down
2 changes: 1 addition & 1 deletion src/typeahead/typeahead.directive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ export class TypeaheadDirective implements OnInit, OnDestroy {

// tslint:disable-next-line:no-any
protected keyUpEventEmitter: EventEmitter<string> = new EventEmitter();
protected _matches: TypeaheadMatch[];
protected _matches: TypeaheadMatch[] = [];
protected placement = 'bottom left';

private _typeahead: ComponentLoader<TypeaheadContainerComponent>;
Expand Down