Skip to content

Commit

Permalink
fix(chartist.component): throw error if chart does not have data or type
Browse files Browse the repository at this point in the history
Closes #41

Signed-off-by: Will Soto <[email protected]>
  • Loading branch information
willsoto committed Sep 24, 2016
1 parent dfee547 commit 0c0dea0
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/chartist.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ class ChartistComponent implements OnInit, OnChanges, OnDestroy {
}

ngOnInit(): Promise<ChartInterfaces> {
if (!this.type || !this.data) {
Promise.reject(`Expected at least type and data. Got ${this.type} for type and ${this.data} for data`);
}

return this.renderChart().then((chart) => {
if (this.events !== undefined) {
this.bindEvents(chart);
Expand Down
18 changes: 18 additions & 0 deletions test/chartist.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,4 +147,22 @@ describe('chartist component', function(): void {
expect(instance.chart.update).toHaveBeenCalled();
});
}));

it('should throw an error when missing type', async(() => {
let fixture = TestBed.createComponent(ChartistComponent);
let instance: ChartistComponent = fixture.debugElement.componentInstance;

instance.data = data['Bar'];

expect(instance.ngOnInit).toThrow();
}));

it('should throw an error when missing data', async(() => {
let fixture = TestBed.createComponent(ChartistComponent);
let instance: ChartistComponent = fixture.debugElement.componentInstance;

instance.type = 'Bar';

expect(instance.ngOnInit).toThrow();
}));
});

0 comments on commit 0c0dea0

Please sign in to comment.