Skip to content

Commit

Permalink
fix: Error on disabled option with an empty array #13
Browse files Browse the repository at this point in the history
  • Loading branch information
optimistex committed Feb 8, 2018
1 parent 9954b3f commit 7904729
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
9 changes: 9 additions & 0 deletions src/app/lib/ngx-select/ngx-select.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ describe('NgxSelectComponent', () => {
const selectItemList = (id: number) => fixture.debugElement.nativeElement
.querySelectorAll(`#sel-${id} .ngx-select.open .ngx-select__item`);
const selectItemActive = (id: number) => el(id).querySelector('.ngx-select__item_active');
const selectItemNoFound = (id: number) => el(id).querySelector('.ngx-select__item_no-found');
const selectedItem = (id: number) => el(id).querySelector('.ngx-select__selected-single'); // select multiple = false
const selectedItems = (id: number) => el(id).querySelectorAll('.ngx-select__selected-plural'); // select multiple = true

Expand Down Expand Up @@ -142,6 +143,14 @@ describe('NgxSelectComponent', () => {
expect(selectItemList(2).length).toBe(0);
});

it('should to show "no found message" for empty items', () => {
fixture.componentInstance.select1.items = [];
fixture.detectChanges();
formControl(1).click();
fixture.detectChanges();
expect(selectItemNoFound(1)).toBeTruthy();
});

describe('should have value', () => {
beforeEach(() => {
fixture = TestBed.createComponent(TestNgxSelectComponent);
Expand Down
2 changes: 1 addition & 1 deletion src/app/lib/ngx-select/ngx-select.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,7 @@ export class NgxSelectComponent implements ControlValueAccessor, DoCheck, AfterC
}

protected optionActivate(option: NgxSelectOption): void {
if (!option.disabled) {
if (!option || !option.disabled) {
this.optionActive = option;
}
}
Expand Down

0 comments on commit 7904729

Please sign in to comment.