javascript - How to test functional selectors in redux saga? -
currently possible write reducers , test sagas this:
// selector const selectthingbyid = (state, id) => state.things[id] // in saga const thing = yield select(selectthingbyid, id) // , test expect(gen.next().value) .toequal(select(selectthingbyid, id))
however want use more functional approach write reducers , put data (state) last in arguments:
// selector const selectthingbyid = r.curry((id, state) => state.things[id]) // in saga const thing = yield select(selectthingbyid(id)) // test: fails expect(gen.next().value) .toequal(select(selectthingbyid(id)))
the test fails because selectthingbyid(id)
creates new function everytime.
this solved option prepend arguments select
instead of apending. possible or there way how test such selectors?
you need call selector factory using call
effect can inject right function saga using gen.next(val)
// in saga const selector = yield call(selectthingbyid, id) const thing = yield select(selector) // test const selector = selectthingbyid(id) gen.next(selector) .toequal(call(selectthingbyid, id)) expect(gen.next().value) .toequal(select(selector))
Comments
Post a Comment