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 {
5555
5656 componentWillReceiveProps ( nextProps ) {
5757 // Clone new data & assign internal properties
58- if ( ! deepEqual ( this . props . data , nextProps . data ) ) {
58+ if ( this . props . data !== nextProps . data ) {
5959 this . setState ( {
6060 data : this . assignInternalProperties ( clone ( nextProps . data ) ) ,
6161 } ) ;
Original file line number Diff line number Diff line change @@ -79,18 +79,31 @@ describe('<Tree />', () => {
7979 data : mockData2 ,
8080 } ;
8181 const renderedComponent = mount ( < Tree data = { mockData } /> ) ;
82-
8382 expect ( renderedComponent . instance ( ) . assignInternalProperties ) . toHaveBeenCalledTimes (
8483 mockDataDepth ,
8584 ) ;
86-
8785 renderedComponent . setProps ( nextProps ) ;
88-
8986 expect ( renderedComponent . instance ( ) . assignInternalProperties ) . toHaveBeenCalledTimes (
9087 mockDataDepth + mockData2Depth ,
9188 ) ;
9289 } ) ;
9390
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+
94107 describe ( 'translate' , ( ) => {
95108 it ( 'applies the `translate` prop when specified' , ( ) => {
96109 const fixture = { x : 123 , y : 321 } ;
You can’t perform that action at this time.
0 commit comments