File tree Expand file tree Collapse file tree 2 files changed +17
-4
lines changed Expand file tree Collapse file tree 2 files changed +17
-4
lines changed Original file line number Diff line number Diff line change @@ -55,7 +55,7 @@ export default class Tree extends React.Component {
55
55
56
56
componentWillReceiveProps ( nextProps ) {
57
57
// Clone new data & assign internal properties
58
- if ( ! deepEqual ( this . props . data , nextProps . data ) ) {
58
+ if ( this . props . data !== nextProps . data ) {
59
59
this . setState ( {
60
60
data : this . assignInternalProperties ( clone ( nextProps . data ) ) ,
61
61
} ) ;
Original file line number Diff line number Diff line change @@ -79,18 +79,31 @@ describe('<Tree />', () => {
79
79
data : mockData2 ,
80
80
} ;
81
81
const renderedComponent = mount ( < Tree data = { mockData } /> ) ;
82
-
83
82
expect ( renderedComponent . instance ( ) . assignInternalProperties ) . toHaveBeenCalledTimes (
84
83
mockDataDepth ,
85
84
) ;
86
-
87
85
renderedComponent . setProps ( nextProps ) ;
88
-
89
86
expect ( renderedComponent . instance ( ) . assignInternalProperties ) . toHaveBeenCalledTimes (
90
87
mockDataDepth + mockData2Depth ,
91
88
) ;
92
89
} ) ;
93
90
91
+ it ( "reassigns internal props if `props.data`'s array reference changes" , ( ) => {
92
+ // `assignInternalProperties` recurses by depth: 1 level -> 1 call
93
+ const mockDataDepth = 2 ;
94
+ const nextDataDepth = 2 ;
95
+ const nextData = [ ...mockData ] ;
96
+ nextData [ 0 ] . children . push ( { name : `${ nextData [ 0 ] . children . length } ` } ) ;
97
+ const renderedComponent = mount ( < Tree data = { mockData } /> ) ;
98
+ expect ( renderedComponent . instance ( ) . assignInternalProperties ) . toHaveBeenCalledTimes (
99
+ mockDataDepth ,
100
+ ) ;
101
+ renderedComponent . setProps ( { data : nextData } ) ;
102
+ expect ( renderedComponent . instance ( ) . assignInternalProperties ) . toHaveBeenCalledTimes (
103
+ mockDataDepth + nextDataDepth ,
104
+ ) ;
105
+ } ) ;
106
+
94
107
describe ( 'translate' , ( ) => {
95
108
it ( 'applies the `translate` prop when specified' , ( ) => {
96
109
const fixture = { x : 123 , y : 321 } ;
You can’t perform that action at this time.
0 commit comments