title: Test React component method with setInterval
body: <p>I am using tape, enzyme, jsdom and sinon for my testing purposes. I wanna test the simple thing, that the state was changed after calling the method.</p>
  
  <pre><code>class Countdown extends Component {
        state = {
          count: 0,
          countdownStatus: 'stopped'
        }
  
        componentDidUpdate = (prevProps, prevState) =&gt; {
         if (this.state.countdownStatus !== prevState.countdownStatus) {
           switch (this.state.countdownStatus) {
             case 'started':
               this.startTimer()
               break
            }
          }
        }
  
       startTimer = () =&gt; {
          this.timer = setInterval(() =&gt; {
            const newCount = this.state.count - 1
            this.setState({
              count: newCount &gt;= 0 ? newCount : 0
            })
          }, 1000)
        }
  
        handleSetCountdown = (seconds) =&gt; {
          this.setState({
            count: seconds,
            countdownStatus: 'started'
          })
        }
  
        render () {
          const {count} = this.state
          return (
            &lt;div&gt;
              &lt;Clock totalSeconds={count} /&gt;
              &lt;CountdownForm onSetCountdown={this.handleSetCountdown} /&gt;
            &lt;/div&gt;
          )
        }
      }
  
      export default Countdown
  </code></pre>
  
  <p>And this is not working. It says that it passes but then my last test always hangs for some reason, all test passes but they don't exit. Maybe it is because of setInterval although I don't test it.</p>
  
  <pre><code>test('Countdown =&gt;  should set state to 10, (t) =&gt; {
    t.plan(1)
    const wrapper = shallow(&lt;Countdown /&gt;)
    wrapper.instance().handleSetCountdown(10)
    wrapper.update()
    t.equal(wrapper.state().count, 10)
  })
  </code></pre>
  
  <p><strong>EDIT:</strong> Ok, i figured it down. The tests are not ending because of setInterval. How would I fix this?</p>
  
  <p><strong>EDIT 2:</strong> The solution was pretty simple. I just added </p>
  
  <pre><code>var clock = sinon.useFakeTimers()
  </code></pre>
  
  <p>and all test finish like they should.</p>