{"action":"created","issue":{"url":"https://api.github.com/repos/redux-observable/redux-observable/issues/144","repository_url":"https://api.github.com/repos/redux-observable/redux-observable","labels_url":"https://api.github.com/repos/redux-observable/redux-observable/issues/144/labels{/name}","comments_url":"https://api.github.com/repos/redux-observable/redux-observable/issues/144/comments","events_url":"https://api.github.com/repos/redux-observable/redux-observable/issues/144/events","html_url":"https://github.com/redux-observable/redux-observable/issues/144","id":188070385,"number":144,"title":"A way to write unit tests for redux-observable","user":{"login":"drtimwright","id":7540034,"avatar_url":"https://avatars.githubusercontent.com/u/7540034?v=3","gravatar_id":"","url":"https://api.github.com/users/drtimwright","html_url":"https://github.com/drtimwright","followers_url":"https://api.github.com/users/drtimwright/followers","following_url":"https://api.github.com/users/drtimwright/following{/other_user}","gists_url":"https://api.github.com/users/drtimwright/gists{/gist_id}","starred_url":"https://api.github.com/users/drtimwright/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/drtimwright/subscriptions","organizations_url":"https://api.github.com/users/drtimwright/orgs","repos_url":"https://api.github.com/users/drtimwright/repos","events_url":"https://api.github.com/users/drtimwright/events{/privacy}","received_events_url":"https://api.github.com/users/drtimwright/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":1,"created_at":"2016-11-08T18:39:48Z","updated_at":"2016-11-08T18:54:17Z","closed_at":null,"body":"\r\nHey, just clicked on the \"share a testing idea\" on your page and came here. So am sharing :) \r\n\r\nBasically I had three problems:\r\n\r\n1. How to determine when my middleware had finished processing so that I could trigger non redux events (like changing page URLs on save - am using react-router and there are cases where a component has access to some object and the middleware does not)\r\n\r\n2. How to determine when my middleware had finished processing so I could check expectations in my tests.\r\n\r\n3. How to test what a component should do after the middleware has processed an action\r\n\r\nTo do this, I added a \"callback\" function to my action that is called once an event finishes processing. \r\n\r\nFor # 3, it lets me spy on the store and perform expectations on what the callback function does - so I can test my other code's async behaviour without needing to create a store.\r\n\r\nHope that helps!\r\n\r\nTim\r\n"},"comment":{"url":"https://api.github.com/repos/redux-observable/redux-observable/issues/comments/259225361","html_url":"https://github.com/redux-observable/redux-observable/issues/144#issuecomment-259225361","issue_url":"https://api.github.com/repos/redux-observable/redux-observable/issues/144","id":259225361,"user":{"login":"drtimwright","id":7540034,"avatar_url":"https://avatars.githubusercontent.com/u/7540034?v=3","gravatar_id":"","url":"https://api.github.com/users/drtimwright","html_url":"https://github.com/drtimwright","followers_url":"https://api.github.com/users/drtimwright/followers","following_url":"https://api.github.com/users/drtimwright/following{/other_user}","gists_url":"https://api.github.com/users/drtimwright/gists{/gist_id}","starred_url":"https://api.github.com/users/drtimwright/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/drtimwright/subscriptions","organizations_url":"https://api.github.com/users/drtimwright/orgs","repos_url":"https://api.github.com/users/drtimwright/repos","events_url":"https://api.github.com/users/drtimwright/events{/privacy}","received_events_url":"https://api.github.com/users/drtimwright/received_events","type":"User","site_admin":false},"created_at":"2016-11-08T18:54:17Z","updated_at":"2016-11-08T18:54:17Z","body":"I should also mention that I have a reusable class that does all the callback and incoming stream filtering. That class is configured to call a \"process\" method that does the actual processing. That process method returns a promise - so my tests can test middleware event processing easily. \r\n\r\nThat reusable function looks something like this:\r\n\r\n  controllerMiddleware(actions: Observable<Action>, store: RipStore): Observable<Action> {\r\n    return new Observable<Action>((subscriber: Subscriber<Action>) => {\r\n      actions\r\n        .filter((action: Action) => action.type === this.actionType)\r\n        .forEach(async (action: ActionType) => {\r\n          try {\r\n            const response = await this.processAction(action, subscriber, store);\r\n            action.whenDone(null, response);\r\n          } catch (err) {\r\n            action.whenDone(err);\r\n          }\r\n        });\r\n    });\r\n  };\r\n\r\nFingers crossed it works as expected - I'm very new to redux-observable!"}}
{"actor":{"display_login":"drtimwright"}}