{"record":{"id":"4805807f56eade1a","repo":"redux-saga/redux-saga","slug":"the-task-is-no-longer-running-it-is-str-you-c","errorCode":null,"errorMessage":"The task is no longer Running, it is ${str}. You can't change the status of a task once it is no longer running.","messagePattern":"The task is no longer Running, it is (.+?)\\. You can't change the status of a task once it is no longer running\\.","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/testing-utils/src/index.js","lineNumber":47,"sourceCode":"        const clonedGen = cloneableGenerator(generatorFunc)(...args)\n        history.forEach(({ method, arg }) => clonedGen[method](arg))\n        return clonedGen\n      },\n      return: (value) => record('return', value),\n      throw: (exception) => record('throw', exception),\n    }\n\n    if (typeof Symbol !== 'undefined') {\n      cloneableGen[Symbol.iterator] = () => cloneableGen\n    }\n\n    return cloneableGen\n  }\n\nconst assertStatusRunning = (status) => {\n  if (status !== RUNNING) {\n    const str = statusToStringMap[status]\n    throw new Error(\n      `The task is no longer Running, it is ${str}. You can't change the status of a task once it is no longer running.`,\n    )\n  }\n}\n\nexport function createMockTask() {\n  let status = RUNNING\n  let taskResult\n  let taskError\n\n  return {\n    [TASK]: true,\n    isRunning: () => status === RUNNING,\n    isCancelled: () => status === CANCELLED,\n    isAborted: () => status === ABORTED,\n    result: () => taskResult,\n    error: () => taskError,\n    cancel: () => {","sourceCodeStart":29,"sourceCodeEnd":65,"githubUrl":"https://github.com/redux-saga/redux-saga/blob/b603028ae2d6f1f96f94fb4f016bde3fa32d6a2d/packages/testing-utils/src/index.js#L29-L65","documentation":"@redux-saga/testing-utils' mock tasks expose methods like setResult, cancel, and reject that mutate task state. These operations are only valid while the task status is RUNNING, so assertStatusRunning throws with the actual status (e.g. Cancelled, Aborted, Done) when you attempt to change a finished or cancelled mock task's status.","triggerScenarios":"Calling mockTask.setResult(value), mockTask.reject(error), or mockTask.cancel() on a mock task created by createMockTask after its status was set to a non-RUNNING value (Cancelled, Aborted, Done).","commonSituations":"Unit tests that resolve/reject a mock task and then try to resolve it again (e.g. in a second assertion); reusing a single mock task across test phases; accidentally cancelling a mock task and then attempting setResult.","solutions":["Create a fresh mock task with createMockTask() for each state transition in your test instead of reusing one.","Set all needed results on the mock task before marking it cancelled/done, or don't set the non-running status until done driving it.","Restructure the test so each saga outcome (resolve, reject, cancel) is asserted with its own task instance.","Check task.status() before mutating to confirm it is still RUNNING."],"exampleFix":"// before\nconst task = createMockTask()\ntask.cancel()\ntask.setResult(data) // throws: task is Cancelled\n// after\nconst task = createMockTask()\ntask.setResult(data)\ntask.cancel()","handlingStrategy":"validation","validationCode":"function assertMutableTask(task) {\n  if (task.status() !== 'RUNNING') {\n    throw new Error(`Mock task is ${task.status()}; create a new mock task to mutate`)\n  }\n}","typeGuard":"const isRunningMockTask = (task) => typeof task.status === 'function' && task.status() === 'RUNNING'","tryCatchPattern":"try {\n  mockTask.setResult(value)\n} catch (e) {\n  if (e.message.includes('no longer Running')) {\n    mockTask = createMockTask()\n    mockTask.setResult(value)\n  } else {\n    throw e\n  }\n}","preventionTips":["Use a fresh createMockTask() per test case or per state transition","Check task.status() before setResult/reject/cancel on shared mocks","Never reuse one mock task for resolve-then-cancel flows","Write tests so each saga outcome has its own mock instance"],"tags":["redux-saga","testing-utils","mock-task","task-status"],"backgroundTag":"invalid-task-state-transition","analyzedSha":"b603028ae2d6f1f96f94fb4f016bde3fa32d6a2d","analyzedAt":"2026-09-01T05:30:25.240Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}