title: Unable to reach 100% branch coverage in JEST + ENZYME
body: <p>I have below code in my LoadingIndicator test file. I am using JEST + Enzyme to test the LoadingIndicator container class.</p>
  
  <p>I have been struggling to get the branch coverage to 100%. It is stuck on 91%. The branch that I am unable to cover is  <strong>if (!this.timeoutID)</strong> in the LoadingIndicator container class. Please help me understand what I am missing here.</p>
  
  <pre><code>import ...;
  
  import ConnectedLoadingIndicator,{ LoadingIndicator } from './loadingIndicator';
  
  jest.useFakeTimers();
  
  describe('LoadingIndicator unconnected container component', () =&gt; {
  
    let wrapper;
    let instance;
    beforeEach(() =&gt; {
  
                      wrapper = shallow(&lt;LoadingIndicator
                                          loading='true'
                                          error='false' /&gt;);
  
                      instance = wrapper.instance();
                    });
  
    it('checks loadingIndicator is hidden on loading false', () =&gt; {
      wrapper.setProps({ loading: false, error: false });
      expect(instance.state.showIndicator).toBe(false);
      expect(wrapper.find('.loading-hidden').length).toEqual(1);
    });
  
    it('checks loadingIndicator is shown after timer runs', () =&gt; {
      wrapper.setProps({ loading: true, error: false });
      jest.runOnlyPendingTimers();
      expect(instance.state.showIndicator).toBe(true);
      expect(wrapper.find('.loading-show').length).toEqual(1);
    });
  
    it('checks loadingIndicator is hidden on error true', () =&gt; {
      wrapper.setProps({ loading: true, error: true });
      expect(instance.state.showIndicator).toBe(false);
      expect(wrapper.find('.loading-hidden').length).toEqual(1);
    });
  
    it('checks destroyTimer behavior on loading false and error false', () =&gt; {
      wrapper.setProps({ loading: false, error: false });
      expect(instance.timeoutID).toBe(null);
      expect(instance.state.showIndicator).toBe(false);
    });
  
  });
  </code></pre>
  
  <p>LoadingIndicator Container class</p>
  
  <pre><code>import ...;
  
  import LoadingIndicatorComponent from '../../../../components/loadingIndicator';
  
  export class LoadingIndicator extends Component {
  
    constructor(props) {
      super(props);
      this.timeoutID = null;
      this.state = {
        showIndicator: false,
      };
    }
  
    componentDidMount() {
      this.ensureTimer(this.props);
    }
  
    componentWillUnmount() {
      this.destroyTimer();
    }
  
    componentWillReceiveProps(props) {
      if (props.loading !== this.props.loading
            || props.error !== this.props.error) {
        this.ensureTimer(props);
      }
    }
  
    ensureTimer(props) {
      if (props.loading &amp;&amp; !props.error) {
        if (!this.timeoutID) {
          this.timeoutID = setTimeout(() =&gt; {
            this.timeoutID = null;
            this.setState({ showIndicator: true });
          }, props.timeoutPeriod);
        }
      } else {
        this.destroyTimer();
      }
    }
  
    destroyTimer() {
      clearTimeout(this.timeoutID);
      this.timeoutID = null;
      this.setState({ showIndicator: false });
    }
  
    render() {
      console.log(this.state.showIndicator);
      return (
        &lt;div className =
          {`${this.state.showIndicator ? 'loading-show' : 'loading-hidden'}`}&gt;
          &lt;LoadingIndicatorComponent&gt;
            Loading...
          &lt;/LoadingIndicatorComponent&gt;
        &lt;/div&gt;
      );
    }
  
  }
  
  const mapStateToProps = (state) =&gt; ({
    loading: isLoading(state),
    error: hasError(state),
  });
  
  // timeoutPeriod of 1000 is for showing loading indicator after 1000ms
  LoadingIndicator.defaultProps = {
    timeoutPeriod: 1000,
  };
  
  export default connect(mapStateToProps)(LoadingIndicator);
  </code></pre>