Skip to content

Commit

Permalink
fix(select): prevent dispose call on uninitialized properties (#1340)
Browse files Browse the repository at this point in the history
  • Loading branch information
yggg committed Apr 8, 2019
1 parent ffd386c commit a7a158d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/framework/theme/components/select/select.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -345,8 +345,12 @@ export class NbSelectComponent<T> implements OnInit, AfterViewInit, AfterContent
ngOnDestroy() {
this.alive = false;

this.ref.dispose();
this.triggerStrategy.destroy();
if (this.ref) {
this.ref.dispose();
}
if (this.triggerStrategy) {
this.triggerStrategy.destroy();
}
}

show() {
Expand Down
5 changes: 5 additions & 0 deletions src/framework/theme/components/select/select.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,11 @@ describe('Component: NbSelectComponent', () => {
expect(selectButton.textContent).toEqual(selectedOption.value.toString());
}));

it(`should not call dispose on uninitialized resources`, () => {
const selectFixture = new NbSelectComponent(null, null, null, null, null, null);
expect(() => selectFixture.ngOnDestroy()).not.toThrow();
});

describe('NbOptionComponent', () => {
it('should ignore selection change if destroyed', () => {
const selectFixture = TestBed.createComponent(NbReactiveFormSelectComponent);
Expand Down

0 comments on commit a7a158d

Please sign in to comment.