@@ -57,7 +57,7 @@ const states = [
5757
5858describe ( '<UIView>' , ( ) => {
5959 describe ( '(unmounted)' , ( ) => {
60- let router ;
60+ let router : UIRouterReact ;
6161 beforeEach ( ( ) => {
6262 router = new UIRouterReact ( ) ;
6363 router . plugin ( memoryLocationPlugin ) ;
@@ -98,12 +98,12 @@ describe('<UIView>', () => {
9898 } ) ;
9999
100100 describe ( '(mounted)' , ( ) => {
101- let router ;
101+ let router : UIRouterReact ;
102102 beforeEach ( ( ) => {
103103 router = new UIRouterReact ( ) ;
104104 router . plugin ( servicesPlugin ) ;
105105 router . plugin ( memoryLocationPlugin ) ;
106- states . forEach ( state => router . stateRegistry . register ( state ) ) ;
106+ states . forEach ( state => router . stateRegistry . register ( state as ReactStateDeclaration ) ) ;
107107 } ) ;
108108
109109 it ( 'renders its State Component' , ( ) => {
@@ -123,7 +123,7 @@ describe('<UIView>', () => {
123123 name : '__state' ,
124124 component : Comp ,
125125 resolve : [ { resolveFn : ( ) => true , token : 'myresolve' } ] ,
126- } ) ;
126+ } as ReactStateDeclaration ) ;
127127 const wrapper = mount (
128128 < UIRouter router = { router } >
129129 < UIView />
@@ -141,7 +141,7 @@ describe('<UIView>', () => {
141141 name : '__state' ,
142142 component : Comp ,
143143 resolve : [ { token : 'foo' , resolveFn : ( ) => 'bar' } ] ,
144- } ) ;
144+ } as ReactStateDeclaration ) ;
145145 const wrapper = mount (
146146 < UIRouter router = { router } >
147147 < UIView />
@@ -158,7 +158,7 @@ describe('<UIView>', () => {
158158 name : '__state' ,
159159 component : Comp ,
160160 resolve : [ { token : 'transition' , resolveFn : ( ) => null } ] ,
161- } ) ;
161+ } as ReactStateDeclaration ) ;
162162
163163 await router . stateService . go ( '__state' ) ;
164164
@@ -268,5 +268,35 @@ describe('<UIView>', () => {
268268 await router . stateService . go ( 'withrenderprop' ) ;
269269 expect ( wrapper . html ( ) ) . toEqual ( `<div><span>withrenderprop</span><span>bar</span></div>` ) ;
270270 } ) ;
271+
272+ it ( 'unmounts the State Component when calling stateService.reload(true)' , async ( ) => {
273+ const componentDidMountWatcher = jest . fn ( ) ;
274+ const componentWillUnmountWatcher = jest . fn ( ) ;
275+ class TestUnmountComponent extends React . Component {
276+ componentDidMount ( ) {
277+ componentDidMountWatcher ( ) ;
278+ }
279+ componentWillUnmount ( ) {
280+ componentWillUnmountWatcher ( ) ;
281+ }
282+ render ( ) {
283+ return < div /> ;
284+ }
285+ }
286+ const testState = {
287+ name : 'testunmount' ,
288+ component : TestUnmountComponent ,
289+ } ;
290+ router . stateRegistry . register ( testState ) ;
291+ const wrapper = mount (
292+ < UIRouter router = { router } >
293+ < UIView />
294+ </ UIRouter > ,
295+ ) ;
296+ await router . stateService . go ( 'testunmount' ) ;
297+ await router . stateService . reload ( 'testunmount' ) ;
298+ expect ( componentDidMountWatcher ) . toHaveBeenCalledTimes ( 2 ) ;
299+ expect ( componentWillUnmountWatcher ) . toHaveBeenCalledTimes ( 1 ) ;
300+ } ) ;
271301 } ) ;
272302} ) ;
0 commit comments