File tree Expand file tree Collapse file tree 1 file changed +25
-0
lines changed Expand file tree Collapse file tree 1 file changed +25
-0
lines changed Original file line number Diff line number Diff line change @@ -723,4 +723,29 @@ describe('ReactUpdates', function() {
723723 expect ( a . state . x ) . toBe ( 1 ) ;
724724 expect ( a . getDOMNode ( ) . textContent ) . toBe ( 'A1' ) ;
725725 } ) ;
726+
727+ it ( 'calls componentWillReceiveProps setState callback properly' , function ( ) {
728+ var callbackCount = 0 ;
729+ var A = React . createClass ( {
730+ getInitialState : function ( ) {
731+ return { x : this . props . x } ;
732+ } ,
733+ componentWillReceiveProps : function ( nextProps ) {
734+ var newX = nextProps . x ;
735+ this . setState ( { x : newX } , function ( ) {
736+ // State should have updated by the time this callback gets called
737+ expect ( this . state . x ) . toBe ( newX ) ;
738+ callbackCount ++ ;
739+ } ) ;
740+ } ,
741+ render : function ( ) {
742+ return < div > { this . state . x } </ div > ;
743+ }
744+ } ) ;
745+
746+ var container = document . createElement ( 'div' ) ;
747+ React . renderComponent ( < A x = { 1 } /> , container ) ;
748+ React . renderComponent ( < A x = { 2 } /> , container ) ;
749+ expect ( callbackCount ) . toBe ( 1 ) ;
750+ } ) ;
726751} ) ;
You can’t perform that action at this time.
0 commit comments