Fix ChannelLoader prop warning (#5055)

* Fix ChannelLoader prop warning

* Missing semicolon
This commit is contained in:
Miguel Alatzar 2020-12-18 13:48:28 -07:00 committed by GitHub
parent 673f10770d
commit f577685264
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 20 additions and 8 deletions

View file

@ -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() {

View file

@ -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(<ChannelLoader {...baseProps}/>);
const instance = wrapper.instance();
shallow(<ChannelLoader {...baseProps}/>);
expect(setTimeout).not.toHaveBeenCalled();
expect(setInterval).not.toHaveBeenCalled();
const props = {
...baseProps,
retryLoad: jest.fn(),
};
const wrapper = shallow(<ChannelLoader {...props}/>);
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(<ChannelLoader {...baseProps}/>);
const props = {
...baseProps,
retryLoad: jest.fn(),
};
const wrapper = shallow(<ChannelLoader {...props}/>);
const instance = wrapper.instance();
instance.componentWillUnmount();