File tree Expand file tree Collapse file tree 2 files changed +64
-3
lines changed Expand file tree Collapse file tree 2 files changed +64
-3
lines changed Original file line number Diff line number Diff line change @@ -14,6 +14,62 @@ describe('Chart re-rendering', () => {
1414 expect ( updateRequired ) . toBeTruthy ( ) ;
1515 } ) ;
1616
17+ it ( 'required when data is changed in an inner object/array of the data' , ( ) => {
18+ const originalData = {
19+ "data" : {
20+ "labels" : [
21+ 1
22+ ] ,
23+ "datasets" : [
24+ {
25+ "label" : "a" ,
26+ "backgroundColor" : "#36A2EB" ,
27+ "data" : [
28+ 122968
29+ ]
30+ } ,
31+ {
32+ "label" : "b" ,
33+ "backgroundColor" : "#FF6384" ,
34+ "data" : [
35+ 14738
36+ ]
37+ }
38+ ]
39+ } ,
40+ "type" : "bar" ,
41+ "legend" : {
42+ "display" : true ,
43+ "position" : "bottom"
44+ }
45+ }
46+ // The new data has only one data set instead of two
47+ const newData = {
48+ "data" : {
49+ "labels" : [
50+ 1
51+ ] ,
52+ "datasets" : [
53+ {
54+ "label" : "a" ,
55+ "backgroundColor" : "#36A2EB" ,
56+ "data" : [
57+ 122968
58+ ]
59+ }
60+ ]
61+ } ,
62+ "type" : "bar" ,
63+ "legend" : {
64+ "display" : true ,
65+ "position" : "bottom"
66+ }
67+ }
68+ const chart = new ChartComponent ( originalData ) ;
69+ const updateRequired = chart . shouldComponentUpdate ( newData ) ;
70+ expect ( updateRequired ) . toBeTruthy ( ) ;
71+ } ) ;
72+
1773 it ( 'required when chart options change' , ( ) => {
1874 const chart = new ChartComponent ( { type : 'bar' , options : { hover : { mode : 'single' } } } ) ;
1975 const updateRequired = chart . shouldComponentUpdate ( { type : 'bar' , options : { hover : { mode : 'label' } } } ) ;
Original file line number Diff line number Diff line change @@ -22,10 +22,15 @@ const deepEqual = (objA, objB) => {
2222 }
2323
2424 let keysA = Object . keys ( objA ) ;
25+ let keysB = Object . keys ( objB ) ;
26+ let allKeys = keysA . concat ( keysB ) ;
2527
26- // Test for A's keys different from B.
27- for ( let i = 0 ; i < keysA . length ; i ++ ) {
28- if ( ! hasOwnProperty . call ( objB , keysA [ i ] ) ) {
28+ // Verify both objects have all the keys
29+ for ( let i = 0 ; i < allKeys . length ; i ++ ) {
30+ if ( ! hasOwnProperty . call ( objB , allKeys [ i ] ) ) {
31+ return false ;
32+ }
33+ if ( ! hasOwnProperty . call ( objA , allKeys [ i ] ) ) {
2934 return false ;
3035 }
3136 }
You can’t perform that action at this time.
0 commit comments