redux saga testing cancel(task): argument [object Object] is not a valid Task object

Problem: cancel(task): argument [object Object] is not a valid Task object

(HINT: if you are getting these errors in tests, consider using createMockTask from @redux-saga/testing-utils)

Code:

while (true) {
 take(DriversActionTypes.DRIVERS_SOCKET_OFF))

    const emitAction = yield fork(Read_Emit_Or_Write_Emit, socket);
   
    
    yield take(DriversActionTypes.DRIVERS_SOCKET_OFF);

    
    yield cancel(emitAction); 

    yield call(disconnect, socket);
  }


Solution:



while (true) {
 take(DriversActionTypes.DRIVERS_SOCKET_OFF))

    const emitAction = yield fork(Read_Emit_Or_Write_Emit, socket);
   
    
    yield take(DriversActionTypes.DRIVERS_SOCKET_OFF);

    
  

    yield call(disconnect, socket);
    yield cancel(emitAction); 
    //Basically always put cancel towards the bottom

  }

Couldn't find why testing results in this problem??? Searched all over the internet for a solutions. Until, I searched the redux saga docs and realized cancel should always be at the bottom! .... Hopefully this will help a poor soul out there when they do npm test (: