1
1
import { ComponentFixture , TestBed } from '@angular/core/testing' ;
2
2
3
3
import { ChartjsComponent } from './chartjs.component' ;
4
+ import { Chart , registerables } from 'chart.js' ;
4
5
5
6
describe ( 'ChartjsComponent' , ( ) => {
6
7
let component : ChartjsComponent ;
@@ -25,12 +26,13 @@ describe('ChartjsComponent', () => {
25
26
} ;
26
27
27
28
beforeEach ( async ( ) => {
29
+ Chart . register ( ...registerables ) ;
30
+
28
31
await TestBed . configureTestingModule ( {
29
32
declarations : [ ChartjsComponent ]
30
33
} ) . compileComponents ( ) ;
31
34
32
- // Chart.register(...registerables);
33
-
35
+ // @ts -ignore
34
36
fixture = TestBed . createComponent ( ChartjsComponent ) ;
35
37
component = fixture . componentInstance ;
36
38
component . data = undefined ;
@@ -46,9 +48,9 @@ describe('ChartjsComponent', () => {
46
48
it ( 'chart should receive data' , ( ) => {
47
49
component . data = { ...data } ;
48
50
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 ) ;
52
54
} ) ;
53
55
54
56
it ( 'chart to Base64Image' , ( ) => {
@@ -61,10 +63,6 @@ describe('ChartjsComponent', () => {
61
63
} ) ;
62
64
63
65
it ( 'chart should update on data change' , ( ) => {
64
- component . data = { ...data } ;
65
- // todo
66
- fixture . detectChanges ( ) ;
67
-
68
66
component . data = {
69
67
...data ,
70
68
labels : [ 'Jan' , 'Feb' , 'Mar' , 'Apr' , 'May' ] ,
@@ -73,15 +71,8 @@ describe('ChartjsComponent', () => {
73
71
{ ...data . datasets [ 0 ] , data : [ 55 , 44 , 55 , 66 , 22 ] }
74
72
]
75
73
} ;
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 ] } ) ;
83
74
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 ) ;
86
77
} ) ;
87
78
} ) ;
0 commit comments