redux-saga
の使い方を教えていますが、同時にユニットテスト、特にJestを教えています。redux-saga-test-planでredux-saga関数をテストする方法を理解できません
http://yelouafi.github.io/redux-saga/docs/advanced/NonBlockingCalls.html
を...そして私自身の目的のためにそれを修正:私はここで、Reduxの-サガのドキュメントからサンプルサガを取りました。ユーザーがログインしているかどうかを関数が認識しないため、ログインまたはログアウトアクションのいずれかをリッスンしてから、適切な処置を実行する単純な認証ハンドラであると考えられます。私は、アプリケーション内の関数をテストし、それは素晴らしいと期待どおり機能するように見えます。関数は次のとおりです。
これはかなり簡単ですが、テストするのは苦労しています。私が間違っサガをやっている、または私はサガをテストする方法を理解していない、または佐賀のこの種をテストするので、どちらか
it ('authFlow() should work with successful login and then successful logout',() => {
const mockCredentials = {username: 'User', password: 'goodpassword'};
testSaga(stateAuth.watcher)
//this should test the first 'yield', which is waiting for LOGIN or LOGOUT. It works
.next().take(['LOGIN', 'LOGOUT'])
// This should test 'authorizeWithRemoteServer', and appears to do that properly
.next({type: 'LOGIN', payload: mockCredentials}).fork(stateAuth.authorizeWithRemoteServer, mockCredentials)
// This should reflect 'yield take' after the 'yield fork', and does so
.next().take(['LOGOUT', 'LOGIN_FAIL'])
/* this is where I don't understand what's happening. What I would think I should do is something like this, if I want to test the logout path:
.next({type: 'LOGOUT'}).cancel(createMockTask())
...but that results in the following, perhaps predictable, error:
cancel(task): argument task is undefined
What I found does make the test not fail is the following line, but
I do not understand why it works. The fact that it matches
"take(['LOGIN', 'LOGOUT'])" indicates that it has
looped back to the top of the generator
*/
.next(createMockTask()).take(['LOGIN', 'LOGOUT'])
})
本当にハードにされています。以下は、私の冗談ベースのテストスクリプトの注釈付きバージョンです。おそらく実用的ではありません。
ここで何が起こっているのですか?前もって感謝します!
ありがとうございます!明日私が仕事に戻ったときに私はテストをします。 – hairbo
アサーション4は失敗しました:私はあなたの提案を(感謝!)、試みたが、私に近づくが、今すぐ '.next({type:actions.LOGOUT})cancel(createMockTask())'キャンセル効果は一致しませんが、 "expected"と "actual"の値が一致します。私は、次回のコメントで実際のものと予想されるものの内容を投稿します。 – hairbo
期待値: {'@@ redux-saga/TASK':true、isRunning:[関数:isRunning]、結果:[関数:結果]、エラー:[関数:エラー]、setRunning:[関数:setRunning]、setResult [機能:setResult]、setError:[機能:setError]} 実際: {'@@ redux-saga/TASK':true、isRunning:[機能:isRunning]、結果:[機能:結果]、エラー: [Function:error]、setRunning:[Function:setRunning]、setResult:[Function:setResult]、setError:[機能:setError]} – hairbo