I am testing my redux-saga-flow, and I have an issue with testing selector method with select.
Selector
const selector = (state) => {
console.log("selector");
return data;
}
Redux saga flow
export function* testedSagaFlow() {
const data = yield select(selector);
if (!data) {
return;
}
yield put (otherAction)
...
}
Test for flow
test("Get data from store", () => {
return expectSaga(testedSagaFlow)
.provide([[mathchers.select.selector(selector), null]])
.select(selector)
.not.put(otherAction)
.run()
})
After running a test, a do not have console.log("selector"); and also this line of code did not covered by test.
How can I test a selectors?
The same does not work with unit test.
test("Unit test flow", () => {
const saga = testSaga(testedSagaFlow);
saga
.next()
.select(selector)
.next(null)
.isDone()
})
"redux-saga-test-plan": "^4.0.1".Option 1. Use withState:
Option 2. Use static provider
E.g.
saga.ts:saga.test.ts:Test result: