{"library":"redux-saga-test-engine","title":"Redux Saga Test Engine","description":"redux-saga-test-engine is a testing utility designed to simplify the process of testing Redux Saga generator functions. It provides a structured API for collecting specific Redux Saga effects (like `PUT` and `CALL`) and mapping yielded effects to predefined return values, eliminating the need for manual iteration over generator steps. The current stable version is 3.0.0. While no explicit release cadence is stated, major versions introduce breaking changes to the top-level API, with minor versions providing feature enhancements and bug fixes. It differentiates itself from alternatives like `redux-saga-test` and `redux-saga-test-plan` by offering a distinct approach to effect collection and environment stubbing, aiming for a more direct and less verbose testing experience, particularly when focusing on the effects a saga produces rather than its step-by-step execution.","language":"javascript","status":"active","last_verified":"Sun Apr 19","install":{"commands":["npm install redux-saga-test-engine"],"cli":null},"imports":["import { createSagaTestEngine } from 'redux-saga-test-engine'","import { collectPuts } from 'redux-saga-test-engine'","import { stub } from 'redux-saga-test-engine'","import { throwError } from 'redux-saga-test-engine'"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"import { createSagaTestEngine } from 'redux-saga-test-engine';\nimport { select, call, put } from 'redux-saga/effects';\n\n// Mock API and selectors for the example\nconst API = {\n  doWeLovePuppies: () => ({ answer: 'Of course we do!' })\n};\nconst getPuppy = () => ({ barks: true, cute: 'Definitely' });\nconst petPuppy = (puppy) => ({ type: 'PET_PUPPY', payload: puppy });\nconst hugPuppy = (puppy) => ({ type: 'HUG_PUPPY', payload: puppy });\n\n// The saga to be tested\nfunction* sagaToTest(action) {\n  const puppyState = yield select(getPuppy);\n  const apiResponse = yield call(API.doWeLovePuppies);\n\n  if (puppyState.cute && apiResponse.answer) {\n    yield put(petPuppy(puppyState));\n    yield put(hugPuppy(puppyState));\n  }\n}\n\n// Choose which effect types you want to collect from the saga.\nconst collectEffects = createSagaTestEngine(['PUT', 'CALL']);\n\n// Define environment mappings and initial action\nconst initialAction = { type: 'START_SAGA' };\nconst envMapping = [\n  [select(getPuppy), { barks: true, cute: 'Definitely' }],\n  [call(API.doWeLovePuppies), { answer: 'Of course we do!' }]\n];\n\nconst actualEffects = collectEffects(\n  sagaToTest,\n  envMapping,\n  initialAction\n);\n\nconsole.log(JSON.stringify(actualEffects, null, 2));\n/*\nExpected output (simplified):\n[\n  { \"@@redux-saga/IO\": true, \"call\": { \"args\": [], \"fn\": {} } }, // call(API.doWeLovePuppies)\n  { \"@@redux-saga/IO\": true, \"put\": { \"action\": { \"type\": \"PET_PUPPY\", \"payload\": { \"barks\": true, \"cute\": \"Definitely\" } } } },\n  { \"@@redux-saga/IO\": true, \"put\": { \"action\": { \"type\": \"HUG_PUPPY\", \"payload\": { \"barks\": true, \"cute\": \"Definitely\" } } } }\n]\n*/","lang":"javascript","description":"Demonstrates basic usage of `createSagaTestEngine` to test a Redux Saga, including how to collect specific effect types and provide mock responses for `select` and `call` effects, effectively isolating the saga logic.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}