Skip to content

Commit 7dfc87c

Browse files
committed
chore(test): add test for stateService.reload()
1 parent 1fba8ef commit 7dfc87c

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

src/components/__tests__/UIView.test.tsx

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)