-
-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Create examples & tests for tasks #45
Conversation
FYI the main difficulties in the test start to happen here: https://github.com/yelouafi/redux-saga/pull/45/files#diff-fe2186b9207791d7c78cdf4eb20515feR25 |
Also I havent used tape before so I think the "integration test" never ends for some reason, my mocha/chai test has a clean exit |
@mjrussell Thanks for raising this issue. If I understand the main problem is: how to resume the generator with a dummy result of the fork. Put in other words how to mock the result of a fork task. right ? |
@yelouafi Thanks for the reply. Yeah I think the core of the issue is on testing the fork task, and I like your proposed syntax on #47. I am also curious as to why this passes on 0.4.1 and not on 0.5.0, was there a breaking change in how In general would you tell people to avoid using the |
Here's the output running against master (same for 0.5.0) and the branch
|
I think the issue starts from here https://github.com/yelouafi/redux-saga/pull/45/files#diff-fe2186b9207791d7c78cdf4eb20515feR83 In 0.4.1, you can call const task = runSaga(cancellableSaga(syncSaga), storeIO(store)); So this call wont fail https://github.com/yelouafi/redux-saga/pull/45/files#diff-fe2186b9207791d7c78cdf4eb20515feR42 This is to provide an uniform support to all those function for providing context (this). Also it's much simpler to test equality on
In unit testing yes, IMO, it's more reliable and predictable. |
Just some thoughts as I work through these problems myself... I'm not sure that a I'm in a pinch where my
On the other hand, if we want a unit-style test (which I am not a fan of ... I don't care that y was invoked and z were arguments, I want to know that invoking x returned the appropriate thing in the appropriate shape, or failed and threw the correct error, etc), we have to export all the sub-step/nested generators along the way. Exporting those generators places a burden on the app code - whether it's something cheesy like "if this feature-saga exports functions like _function, don't fork it from the root reducer", or something more complicated/orthogonal. edits: |
Aha! Thanks, updated and working now. |
FYI. 0.6.0 added an utility functin |
@yelouafi awesome thanks, I can close this then unless it would be worth cleaning it up with the examples and new way for mocking forks |
I think it'd be util to include. But maybe we should change the title |
Will do! |
Sorry I didn't get around to this sooner, been busy. I think theres a benefit to add some advanced testing examples to the docs/examples and will open a new PR when I find a little more time. |
No worry :) |
This does not have to be merged, just using it as a tool for discussion
First of all, I hope its ok to "abuse" a PR like this. I thought about just making issues but I wanted to code up some of the difficulties I was facing in easy to understand examples. Also using the inline comments should be useful, and maybe it can merged as a fork/task example at some point.
Anyway...I really like redux-saga and Im trying to do some examples and get more familiar with using it (and es7 generators).
Recently I was playing around with the fork/cancel support and found it really useful for a "sync task", like a polling fetch of an item. You might want to stop the fetch at any time, or switch to polling a new item. And you shouldn't really poll more than an item at a time.
I was able to implement this somewhat easily, but ran into some snags when I began writing tests. I found it difficult to write "spec" tests for the fork/task and ended up giving up and using runSaga mainly. I've created an example for tasks that shows the gist of what I was doing and the tests. The Tests include a
***
where I thought something could be improved or I found confusing. This was also done for 0.4.1, I recently tried 0.5.0 but my tests no longer pass (regression?).Some general thoughts:
delay
since its a common pattern - Sure its trivial but at first I tried to import it from saga and didcall(delay, 5)
which ended up just sending an undefined action. Could the input validation be improved oncall
?