11import { ComponentFixture , TestBed } from '@angular/core/testing' ;
22
33import { ChartjsComponent } from './chartjs.component' ;
4+ import { Chart , registerables } from 'chart.js' ;
45
56describe ( 'ChartjsComponent' , ( ) => {
67 let component : ChartjsComponent ;
@@ -25,12 +26,13 @@ describe('ChartjsComponent', () => {
2526 } ;
2627
2728 beforeEach ( async ( ) => {
29+ Chart . register ( ...registerables ) ;
30+
2831 await TestBed . configureTestingModule ( {
2932 declarations : [ ChartjsComponent ]
3033 } ) . compileComponents ( ) ;
3134
32- // Chart.register(...registerables);
33-
35+ // @ts -ignore
3436 fixture = TestBed . createComponent ( ChartjsComponent ) ;
3537 component = fixture . componentInstance ;
3638 component . data = undefined ;
@@ -46,9 +48,9 @@ describe('ChartjsComponent', () => {
4648 it ( 'chart should receive data' , ( ) => {
4749 component . data = { ...data } ;
4850 fixture . detectChanges ( ) ;
49- expect ( component . chart ?. data . labels ?. length ) . toBe ( 7 ) ;
50- expect ( component . chart ?. data . labels ) . toEqual ( labels ) ;
51- expect ( component . chart ?. data . datasets [ 0 ] ?. data . length ) . toBe ( 7 ) ;
51+ expect ( component . chart ?. config . data . labels ?. length ) . toBe ( 7 ) ;
52+ expect ( component . chart ?. config . data . labels ) . toEqual ( labels ) ;
53+ expect ( component . chart ?. config . data . datasets [ 0 ] ?. data . length ) . toBe ( 7 ) ;
5254 } ) ;
5355
5456 it ( 'chart to Base64Image' , ( ) => {
@@ -61,10 +63,6 @@ describe('ChartjsComponent', () => {
6163 } ) ;
6264
6365 it ( 'chart should update on data change' , ( ) => {
64- component . data = { ...data } ;
65- // todo
66- fixture . detectChanges ( ) ;
67-
6866 component . data = {
6967 ...data ,
7068 labels : [ 'Jan' , 'Feb' , 'Mar' , 'Apr' , 'May' ] ,
@@ -73,15 +71,8 @@ describe('ChartjsComponent', () => {
7371 { ...data . datasets [ 0 ] , data : [ 55 , 44 , 55 , 66 , 22 ] }
7472 ]
7573 } ;
76- // todo
77- // @ts -ignore
78- component . chart . data . labels = [ 'Jan' , 'Feb' , 'Mar' , 'Apr' , 'May' ] ;
79- // @ts -ignore
80- component . chart . data . datasets . fill ( { ...data . datasets [ 0 ] , data : [ 42 , 88 , 42 , 66 , 77 ] } ) ;
81- // @ts -ignore
82- component . chart . data . datasets . push ( { ...data . datasets [ 0 ] , data : [ 55 , 44 , 55 , 66 , 22 ] } ) ;
8374 fixture . detectChanges ( ) ;
84- expect ( component . chart ?. data . labels ?. length ) . toBe ( 5 ) ;
85- expect ( component . chart ?. data . datasets [ 1 ] . data . length ) . toBe ( 5 ) ;
75+ expect ( component . chart . config ?. data . labels ?. length ) . toBe ( 5 ) ;
76+ expect ( component . chart . config ?. data . datasets [ 1 ] ? .data . length ) . toBe ( 5 ) ;
8677 } ) ;
8778} ) ;
0 commit comments