@@ -32,6 +32,29 @@ describe('ChartComponent', () => {
3232 await firstValueFrom ( outputToObservable ( component . chartReady ) ) ;
3333 expect ( fixture . debugElement . query ( By . css ( 'svg' ) ) ) . toBeTruthy ( ) ;
3434 } ) ;
35+
36+ it ( 'update series does not re-create the chart' , async ( ) => {
37+ fixture . componentRef . setInput ( 'chart' , { type : 'line' } ) ;
38+ fixture . componentRef . setInput ( 'series' , [ { name : 'series1' , data : [ 10 , 20 , 27 ] } ] ) ;
39+ fixture . componentRef . setInput ( 'xaxis' , { categories : [ 'Jan' , 'Feb' , 'Mar' ] } ) ;
40+ await firstValueFrom ( outputToObservable ( component . chartReady ) ) ;
41+ const chart1 = component . chartInstance ( ) ;
42+ expect ( chart1 ) . toBeTruthy ( ) ;
43+ expect ( fixture . debugElement . queryAll ( By . css ( '.apexcharts-series' ) ) . length ) . toBe ( 1 ) ;
44+
45+ const createElementSpy = spyOn ( component as any , 'createElement' ) . and . callThrough ( ) ;
46+
47+ // Update the series
48+ fixture . componentRef . setInput ( 'series' , [ { name : 'series1' , data : [ 10 , 20 , 30 ] } , { name : 'series2' , data : [ 15 , 25 , 47 ] } ] ) ;
49+ await fixture . whenStable ( ) ;
50+
51+ expect ( createElementSpy ) . not . toHaveBeenCalled ( ) ;
52+ const chart2 = component . chartInstance ( ) ;
53+ expect ( chart2 ) . toBeTruthy ( ) ;
54+ expect ( chart1 ) . withContext ( 'Chart instances should be the same' ) . toBe ( chart2 ) ;
55+
56+ expect ( fixture . debugElement . queryAll ( By . css ( '.apexcharts-series' ) ) . length ) . toBe ( 2 ) ;
57+ } ) ;
3558 } ) ;
3659
3760 describe ( 'when used inside conditional content projection component' , ( ) => {
0 commit comments