{"id":22740167,"url":"https://github.com/a-type/jest-saga","last_synced_at":"2025-10-23T20:03:24.852Z","repository":{"id":57280453,"uuid":"97841552","full_name":"a-type/jest-saga","owner":"a-type","description":"A Jest expect extension to quickly test a redux-saga generator.","archived":false,"fork":false,"pushed_at":"2017-07-20T15:28:03.000Z","size":4,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-05T06:59:46.561Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/a-type.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-07-20T13:57:35.000Z","updated_at":"2018-09-29T11:57:08.000Z","dependencies_parsed_at":"2022-09-19T17:21:15.552Z","dependency_job_id":null,"html_url":"https://github.com/a-type/jest-saga","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/a-type%2Fjest-saga","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/a-type%2Fjest-saga/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/a-type%2Fjest-saga/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/a-type%2Fjest-saga/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/a-type","download_url":"https://codeload.github.com/a-type/jest-saga/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246273518,"owners_count":20750904,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-12-10T23:07:46.063Z","updated_at":"2025-10-23T20:03:24.783Z","avatar_url":"https://github.com/a-type.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# jest-saga\nA Jest `expect` extension to quickly test a `redux-saga` generator.\n\n## Usage\n\nFirst, import the package from your Jest `setupTestFrameworkScriptFile`:\n\n```javascript\nimport 'jest-saga';\n```\n\nAn `expect` extension will now be available in your tests called `toProduceEffects`.\n\nUse the expect extension to make assertions about the effects a saga produces and inject yielded values.\n\n```javascript\nimport exampleSaga from 'sagas/exampleSaga';\n\nexpect(exampleSaga()).toProduceEffects([\n  call(mockApiRequest, 'bar'),\n  put(actionCreator()),\n  call(foo, 'corge'),\n], [\n  mockApiResponse,\n  null,\n  'etc',\n]);\n```\n\n`expect` should be passed the generator function itself for the saga.\n\nThe signature of `toProduceEffects` is `(expectedEffects, yieldedValues = [])`. `expectedEffects` is a list of effects you expect the saga to produce with each iteration. `yieldedValues` is an optional way to inject yielded values from your effects. For instance, in the example above, when the saga calls `yield call(mockApiRequest, 'bar')`, `mockApiResponse` will be returned as the execution continues.\n\n## Advanced Assertions\n\nThere are two more ways you can describe expectations for produced effects:\n\n* `import { ANY } from 'jest-saga'`: `ANY` can be passed instead of an expected effect to match anything. I'm not sure there's a legitimate use case for this (unless laziness is legitimate), as your sagas should produce predictable and expect-able results, but it exists anyway.\n\n* `(value) =\u003e true|false`: Pass a function instead of an effect to do more advanced assertions. You'll receive the `value` from the generator iteration, which should be the yielded effect from the saga in raw form. Here you can make assertions about the contents of the effect, or capture the effect in a scoped variable for further testing. Return `true` if the assertion should pass, `false` if not.\n\nThe latter method can be used for testing forked sagas:\n\n```javascript\nlet forkedSaga;\n\nexpect(parentSaga()).toProduceEffects([\n  (effect) =\u003e {\n    const isFork = !!effect.FORK;\n    if (isFork) {\n      forkedSaga = effect.FORK.fn;\n    }\n    return isFork;\n  },\n]);\n\nexpect(forkedSaga()).toProduceEffects([\n  call(foo, 'bar'),\n]);\n````\n\nIt's not exactly idiomatic. Improvements could be made. But the functionality is available.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fa-type%2Fjest-saga","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fa-type%2Fjest-saga","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fa-type%2Fjest-saga/lists"}