diff --git a/app/components/channel_loader/channel_loader.js b/app/components/channel_loader/channel_loader.js index 61a200bfa..a9656b78a 100644 --- a/app/components/channel_loader/channel_loader.js +++ b/app/components/channel_loader/channel_loader.js @@ -42,7 +42,7 @@ export default class ChannelLoader extends PureComponent { style: CustomPropTypes.Style, theme: PropTypes.object.isRequired, height: PropTypes.number, - retryLoad: PropTypes.func.isRequired, + retryLoad: PropTypes.func, }; constructor(props) { @@ -75,8 +75,10 @@ export default class ChannelLoader extends PureComponent { } componentDidMount() { - this.stillLoadingTimeout = setTimeout(this.showIndicator, 10000); - this.retryLoadInterval = setInterval(this.props.retryLoad, 10000); + if (this.props.retryLoad) { + this.stillLoadingTimeout = setTimeout(this.showIndicator, 10000); + this.retryLoadInterval = setInterval(this.props.retryLoad, 10000); + } } componentWillUnmount() { diff --git a/app/components/channel_loader/channel_loader.test.js b/app/components/channel_loader/channel_loader.test.js index 4f16ec3b0..f2b864868 100644 --- a/app/components/channel_loader/channel_loader.test.js +++ b/app/components/channel_loader/channel_loader.test.js @@ -14,7 +14,6 @@ describe('ChannelLoader', () => { const baseProps = { channelIsLoading: true, theme: Preferences.THEMES.default, - retryLoad: jest.fn(), }; test('should match snapshot', () => { @@ -23,15 +22,26 @@ describe('ChannelLoader', () => { }); test('should call setTimeout and setInterval for showIndicator and retryLoad on mount', () => { - const wrapper = shallow(); - const instance = wrapper.instance(); + shallow(); + expect(setTimeout).not.toHaveBeenCalled(); + expect(setInterval).not.toHaveBeenCalled(); + const props = { + ...baseProps, + retryLoad: jest.fn(), + }; + const wrapper = shallow(); + const instance = wrapper.instance(); expect(setTimeout).toHaveBeenCalledWith(instance.showIndicator, 10000); - expect(setInterval).toHaveBeenCalledWith(baseProps.retryLoad, 10000); + expect(setInterval).toHaveBeenCalledWith(props.retryLoad, 10000); }); test('should clear timer and interval on unmount', () => { - const wrapper = shallow(); + const props = { + ...baseProps, + retryLoad: jest.fn(), + }; + const wrapper = shallow(); const instance = wrapper.instance(); instance.componentWillUnmount();