I'm trying to make a test using redux-test-saga-test-plan
and describe
but I'm having troubles on the yielded return.
The target to being tested is the next slice of code:
const { tenantDocuments, feedDocuments, historicalDocuments } = yield all({
feedDocuments: call(__searchDocument, timezone, validUrl, feedId, 'feed', provider),
tenantDocuments: call(__searchDocument, timezone, validUrl, feedId, 'tenant'),
historicalDocuments: call(__searchDocument, timezone, validUrl, feedId, 'global')
});
__searchDocument
is a generator function and the return comes from another generator , I mean it returns the result of another generator: return yield __getDocuments(documentIds);
The expectSaga
it's something like (I removed a lot of code only leaving the provide part and something of context):
expectSaga(sagas)
.withReducer(reducers)
.withState(getFullState({state}))
.provide([
[matchers.call.fn(Api.prototype.get), dynamic(test.searchApiMock)],
[matchers.call.fn(Api.prototype.post), dynamic(test.documentsApiMock)]
])
.put(operators.setLoading({ loading: true }))
.dispatch(operators.changeStep({ step: "SELECT_FOUND_DOCUMENTS" }))
.hasFinalState(getFullState(state))
.silentRun();
});
As you see I have provided to matchers.call.fn
for 3rd party API calls. And I put on dynamic another function, those functions from now are only returning plain objects and nothing else.
Then, when I try to check the content for example of feedDocuments
.
The content of those vars are like:
{ '@@redux-saga/IO': true,
CALL:
{ context: null,
fn:
{ [Function: sagaWrapper] '@@redux-saga-test-plan/saga-wrapper': true },
args: [ Object [Generator] {}, [Function: refineYieldedValue] ] }
In other hand if I change the sagas code from yield all({...})
to something like:
const feedDocuments = yield __searchDocument(..);
cosnt tenantDocuments = yield __searchDocument(..);
const historicalDocuments = yield __searchDocument(..);
The test & mock works as expected.
Any idea what I'm doing wrong? And why the all
seems that is not properly mocked?