Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save gparlakov/e62d171d04e59723edde4f325be62354 to your computer and use it in GitHub Desktop.
Save gparlakov/e62d171d04e59723edde4f325be62354 to your computer and use it in GitHub Desktop.
test-chart-js.chart-builder-called-chart-constructed.ts
it('should draw the chart on ngAfterViewInit with canvas and config', () => {
// arrange
const r = mockRouter();
const builderSpy = jasmine.createSpy('chart builder')
builderSpy.and.returnValue('the chart');
const c = new ChartComponent(r, builderSpy);
const canvas = document.createElement('canvas');
c.canvas = new ElementRef(canvas);
// act
c.ngAfterViewInit();
// assert
expect(ch).toHaveBeenCalledOnceWith(canvas, jasmine.objectContaining({
type: 'line',
data: {
datasets: [{ [1,2,3,4,5], label: '1' }],
labels: ['1', '2', '3', '4', '5'],
}
}})
);
expect(c.chart).toBeDefined();
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment