Answer the question
In order to leave comments, you need to log in
How to test a saga that returns a promise?
Hello ! There is a saga
export function * handleAwaitAnalyticsEvent (
eventName:string,
timeout:number,
restParams:any,
) {
if (eventName) {
yield call(sendAnalyticsEvent[eventName], restParams);
return new Promise((resolve, reject) => {
const script = document.querySelector<HTMLScriptElement>('script[src*="oko."]');
if(script){
script.onload = () => resolve(true);
}
// script && script.onload = () => resolve(true);
setTimeout(() => reject(false), timeout);
})
}
}
it('should return promise', async () => {
const timerPromise = await handleAwaitAnalyticsEvent(DEFAULTS_ANALYTICS_EVENTS.addToJP, 1000, {
sum: 12,
id: 1,
})
expect(timerPromise).toBe(true)
});
handleAwaitAnalyticsEvent › should return promise
expect(received).toBe(expected) // Object.is equality
Expected: true
Received: {}
69 | id: 1,
70 | })
> 71 | expect(timerPromise).toBe(true)
| ^
72 | });
73 | });
74 |
at Object.<anonymous> (src/common/sagas/__test__/analytics.test.ts:71:26)
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question