I have a web app using Angular CLI. And there is a component called pie-chart-component.
In the pie-chart-component.ts, I'm importing Chart.js
import Chart from 'chart.js';
It works fine from the UI, but when I run npm test
, it doesn't recognize the tag in HTML, and fail the basic karma test that comes with Angular CLI that basically test whether this component is created or not.
Error in Karma:
Failed: Template parse errors:
Can't bind to 'datasets' since it isn't a known property of 'canvas'. ("
<div style="display: block">
part of my spec.ts:
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [PieChartPanelComponent]
})
.compileComponents();
}));
I think I need to add the chart library into providers or imports. But when I try to do that, the compiler will say chart is a type, and I'm trying to use it as a value.
What's the correct way to make Karma test be able to read external libraries and recognize what a tag is?