@@ -859,6 +859,41 @@ describe('React', () => {
859859 expect ( mapStateToPropsCalls ) . toBe ( 1 )
860860 } )
861861
862+ it ( 'should not attempt to set state when dispatching in componentWillUnmount' , ( ) => {
863+ const store = createStore ( stringBuilder )
864+ let mapStateToPropsCalls = 0
865+
866+ /*eslint-disable no-unused-vars */
867+ @connect (
868+ ( state ) => ( { calls : mapStateToPropsCalls ++ } ) ,
869+ dispatch => ( { dispatch } )
870+ )
871+ /*eslint-enable no-unused-vars */
872+ class Container extends Component {
873+ componentWillUnmount ( ) {
874+ this . props . dispatch ( { type : 'APPEND' , body : 'a' } )
875+ }
876+ render ( ) {
877+ return < Passthrough { ...this . props } />
878+ }
879+ }
880+
881+ const div = document . createElement ( 'div' )
882+ ReactDOM . render (
883+ < ProviderMock store = { store } >
884+ < Container />
885+ </ ProviderMock > ,
886+ div
887+ )
888+ expect ( mapStateToPropsCalls ) . toBe ( 1 )
889+
890+ const spy = expect . spyOn ( console , 'error' )
891+ ReactDOM . unmountComponentAtNode ( div )
892+ spy . destroy ( )
893+ expect ( spy . calls . length ) . toBe ( 0 )
894+ expect ( mapStateToPropsCalls ) . toBe ( 1 )
895+ } )
896+
862897 it ( 'should shallowly compare the selected state to prevent unnecessary updates' , ( ) => {
863898 const store = createStore ( stringBuilder )
864899 const spy = expect . createSpy ( ( ) => ( { } ) )
0 commit comments