Reputation: 3095
I Have next saga function
function* fetchData() {
try {
const response = yield call(() => api.get('/names'));
yield put(actions.succeeded(response.data));
} catch (e) {
yield put(actions.failed(e.message));
} finally {
yield delay(3000);
yield put(actions.fetchGraph());
}
}
How I could test yield put(actions.fetchGraph());
in finally block?
Upvotes: 0
Views: 380
Reputation: 2748
I have not tested it, but shouldn't be iterator().next
after an iterator.throw
call the result of the finally
block?
const iterator = fetchData()
assert.deepEqual(
iterator.next().value,
call(api.get, '/names'),
"fetchData should yield an Effect call(api.get, '/names')",
)
const error = { message: 'Fake Error' }
// Throw error and test `catch`
assert.deepEqual(
iterator.throw(error).value,
put(actions.failed(error.message)),
"fetchData should yield an Effect put(actions.failed(error.message))",
)
// After `catch` block, `next()` should continue in `finally`
assert.deepEqual(
iterator.next().value,
delay(3000),
"fetchData should yield an Effect delay(3000)",
)
Upvotes: 1