title: Unit testing redux-saga task cancellation
body: <p>I was wondering if anyone had any tips on how to unit-test the following redux-saga login/logout flow:</p>
  
  <pre><code>let pollingTask = null
  
  function * handleLogin () {
    try {
      const token = yield call(loginHandler)
      pollingTask = yield fork(handlePolls, token)
      yield put('LOGIN_SUCCSES')
    } catch (e) {
      yield put('LOGIN_FAILURE')
    }
  }
  
  function * handlePolls (token) {
    while (true) {
      try {
        yield call(pollHandler, token)
        yield put('POLL_SUCCESS')
      } catch (e) {
        yield put('POLL_FAILURE')
      } finally {
        if (yield cancelled()) {
          yield call(pollCancelled)
        }
      }
    }
  }
  
  function * handleLogout () {
    try {
      yield call(logoutHandler)
      yield cancel(pollingTask) 
      yield put('LOGOUT_SUCCESS')
    } catch (e) {
      yield put('LOGOUT_FAILURE')
    }
  }
  </code></pre>
  
  <p>Since I need to cancel the <code>pollingTask</code> on logout, I tried using <a href="https://github.com/redux-saga/redux-saga/blob/master/docs/advanced/TaskCancellation.md#testing-generators-with-fork-effect" rel="nofollow noreferrer">createMockTask()</a> in my tests but I always get its value as <code>undefined</code> when I invoke the <code>handleLogout()</code> saga, although I know that my <code>handleLogin()</code> would always be started first and it would initialize the <code>pollingTask</code>.</p>
  
  <p>Any help would be much appreciated!</p>