Skip to content

Commit

Permalink
test(select): ensure initial falsy value is selected
Browse files Browse the repository at this point in the history
  • Loading branch information
yggg committed Aug 28, 2019
1 parent 1408988 commit bddc0b8
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion src/framework/theme/components/select/select.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ export class NbNgModelSelectComponent {
<nb-layout>
<nb-layout-column>
<nb-select>
<nb-select [selected]="selectedValue">
<nb-option>No value option</nb-option>
<nb-option [value]="null">undefined value</nb-option>
<nb-option [value]="undefined">undefined value</nb-option>
Expand All @@ -199,6 +199,8 @@ export class NbNgModelSelectComponent {
`,
})
export class NbSelectWithFalsyOptionValuesComponent {
selectedValue;

nanValue = NaN;

@ViewChildren(NbOptionComponent) options: QueryList<NbOptionComponent<any>>;
Expand Down Expand Up @@ -813,6 +815,19 @@ describe('NbSelectComponent - falsy values', () => {
expect(testComponent.truthyOptionElement.nativeElement.querySelector('nb-checkbox')).not.toEqual(null);
});
});

it('should select initial falsy value', fakeAsync(() => {
fixture = TestBed.createComponent(NbSelectWithFalsyOptionValuesComponent);
testComponent = fixture.componentInstance;
select = fixture.debugElement.query(By.directive(NbSelectComponent)).componentInstance;

select.selected = '';
fixture.detectChanges();
flush();

expect(select.selectionModel[0]).toEqual(testComponent.emptyStringOption);
expect(testComponent.emptyStringOption.selected).toEqual(true);
}));
});

describe('NbSelectComponent - Triggers', () => {
Expand Down

0 comments on commit bddc0b8

Please sign in to comment.