{"action":"created","issue":{"url":"https://api.github.com/repos/yelouafi/redux-saga/issues/428","repository_url":"https://api.github.com/repos/yelouafi/redux-saga","labels_url":"https://api.github.com/repos/yelouafi/redux-saga/issues/428/labels{/name}","comments_url":"https://api.github.com/repos/yelouafi/redux-saga/issues/428/comments","events_url":"https://api.github.com/repos/yelouafi/redux-saga/issues/428/events","html_url":"https://github.com/yelouafi/redux-saga/issues/428","id":164464848,"number":428,"title":"How to write high level test for saga? (Subscribe to end of side-effect handling)","user":{"login":"tonyxiao","id":696842,"avatar_url":"https://avatars.githubusercontent.com/u/696842?v=3","gravatar_id":"","url":"https://api.github.com/users/tonyxiao","html_url":"https://github.com/tonyxiao","followers_url":"https://api.github.com/users/tonyxiao/followers","following_url":"https://api.github.com/users/tonyxiao/following{/other_user}","gists_url":"https://api.github.com/users/tonyxiao/gists{/gist_id}","starred_url":"https://api.github.com/users/tonyxiao/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tonyxiao/subscriptions","organizations_url":"https://api.github.com/users/tonyxiao/orgs","repos_url":"https://api.github.com/users/tonyxiao/repos","events_url":"https://api.github.com/users/tonyxiao/events{/privacy}","received_events_url":"https://api.github.com/users/tonyxiao/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":1,"created_at":"2016-07-08T06:04:11Z","updated_at":"2016-07-08T18:10:32Z","closed_at":null,"body":"Current examples of testing sagas are pretty low level. It gives really fine grained control over exactly what a saga does.\r\n\r\nhttps://yelouafi.github.io/redux-saga/docs/advanced/Testing.html\r\n\r\nHowever, I'd like to be able to test my redux setup on a much higher level. Basically how an application would actually consume it\r\n1. Create a store with some initial state\r\n2. Dispatch `actions` to it, expecting `sagas` to do any async work / side effects\r\n3. Let reducers transform state in response to actions dispatched directly / by sagas\r\n4. __Wait until the handling of the actions has finished__\r\n5. Use `selectors` to get the final state and confirm it matches expectations\r\n\r\nHowever, I don't know how to accomplish step 4 with redux saga. \r\n\r\nWith thunk this is super easy.\r\n```javascript\r\nfunction incrementAsync() {\r\n  return dispatch => {\r\n    return new Promise((resolve, reject) => {\r\n      setTimeout(() => {\r\n        // Yay! Can invoke sync or async actions with `dispatch`\r\n        dispatch(increment());\r\n        resolve()\r\n      }, 1000);\r\n    });\r\n  };\r\n}\r\n\r\n// Then in test setup\r\ndescribe('redux store', () => {\r\n  it('increments async by 1', async () => {\r\n    const store = configureStore({counter: 1})\r\n    await store.dispatch(incrementAsync(1))\r\n    const counter = selectCounter(store.getState())\r\n    expect(counter).toBe(2)\r\n  })\r\n})\r\n```\r\n\r\nHowever, it's not clear to me how to dispatch an action and then wait until after `redux-saga` has finished handling side-effects for it. Any ideas?"},"comment":{"url":"https://api.github.com/repos/yelouafi/redux-saga/issues/comments/231432042","html_url":"https://github.com/yelouafi/redux-saga/issues/428#issuecomment-231432042","issue_url":"https://api.github.com/repos/yelouafi/redux-saga/issues/428","id":231432042,"user":{"login":"Baisang","id":6789626,"avatar_url":"https://avatars.githubusercontent.com/u/6789626?v=3","gravatar_id":"","url":"https://api.github.com/users/Baisang","html_url":"https://github.com/Baisang","followers_url":"https://api.github.com/users/Baisang/followers","following_url":"https://api.github.com/users/Baisang/following{/other_user}","gists_url":"https://api.github.com/users/Baisang/gists{/gist_id}","starred_url":"https://api.github.com/users/Baisang/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Baisang/subscriptions","organizations_url":"https://api.github.com/users/Baisang/orgs","repos_url":"https://api.github.com/users/Baisang/repos","events_url":"https://api.github.com/users/Baisang/events{/privacy}","received_events_url":"https://api.github.com/users/Baisang/received_events","type":"User","site_admin":false},"created_at":"2016-07-08T18:10:32Z","updated_at":"2016-07-08T18:10:32Z","body":"Could have the saga dispatch a different action after it handles the actions. This action would invoke a `testSaga` for example that would then examine the state."}}
{"actor":{"display_login":"Baisang"}}