You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi,
First of all, thank you for this great library, it helped me improve the typing and quality of my codebase a lot !
But still do have some question about how to properly test saga that uses typed-redux-saga instead of regular redux-saga.
And the reason behind is that the yield* actually "unwrap" the all combinator, and therefore returns the actual JSON payload of the effect, but the nested call function itself remains a generator around the "real" redux-saga call.
Meaning that we can actually test that the all effect has been yield but we can't check the content of this all effect, greatly degrading the interest of our test.
We can't update the code to unwrap the call effect by hand without losing types inference.
The workaround I use for now is to manually "unwrap" the effect if it is a combinatorEffect (cf: all | race) using the following function.
importtype{CombinatorEffect,CombinatorEffectDescriptor,Effect}from'@redux-saga/types';import{SagaGenerator}from"typed-redux-saga";import{map}from'ramda';functionisCombinatorEffect<T=any,P=any>(effect: Effect<T,P|CombinatorEffectDescriptor<P>>|unknown,): effect is CombinatorEffect<T,P>{return(effectasEffect<T,P|CombinatorEffectDescriptor<P>>).combinator;}exportfunctionunwrapCombinators<EextendsEffect<T,P>|unknown,T,PextendsSagaGenerator<any>|any>(step: E): E{constmapper=(value: P)=>{if(typeof(valueasSagaGenerator<any>).next==='function'){return(valueasSagaGenerator<any>).next().value;}else{returnvalue;}};if(isCombinatorEffect(step)){// @ts-ignore honestly this is way to complex to type this :/constnewPayload=map(mapper,step.payload);return{...step,payload: newPayload};}else{returnstep;}}
My test now looks like this, and passes ✅ , and the saga is still correctly typed.
Hi,
First of all, thank you for this great library, it helped me improve the typing and quality of my codebase a lot !
But still do have some question about how to properly test saga that uses
typed-redux-saga
instead of regularredux-saga
.Let's consider this saga
We can test it pretty easily using this test ( And the test passes ✅ )
But if the original codebase we replace regular redux-saga) (
untypedReduxSaga
) by the typed version the test fail 🟥And the reason behind is that the
yield*
actually "unwrap" theall
combinator, and therefore returns the actual JSON payload of the effect, but the nestedcall
function itself remains a generator around the "real" redux-saga call.Meaning that we can actually test that the
all
effect has been yield but we can't check the content of thisall
effect, greatly degrading the interest of our test.We can't update the code to unwrap the
call
effect by hand without losing types inference.Workaround
The workaround I use for now is to manually "unwrap" the effect if it is a combinatorEffect (cf:
all
|race
) using the following function.My test now looks like this, and passes ✅ , and the saga is still correctly typed.
Suggestions
unwrapCombinators
to help deal with itThe text was updated successfully, but these errors were encountered: