提供所有退货请求@@ redux-saga / IO

时间:2019-08-05 12:18:21

标签: redux-saga redux-saga-test-plan

我正在尝试使用redux-test-saga-test-plandescribe进行测试,但是在收益率上遇到了麻烦。 要测试的目标是下一段代码:

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是一个生成器函数,返回值来自另一个生成器,我的意思是它返回了另一个生成器的结果:return yield __getDocuments(documentIds);

expectSaga类似于(我删除了很多代码,只保留了提供部分和上下文):

  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();
    });

如您所见,我已向matchers.call.fn提供了第三方API调用。而我使用了动态的另一个函数,从现在开始,这些函数仅返回普通对象,而没有其他任何东西。

然后,当我尝试检查feedDocuments等内容时。

这些变量的内容如下:

 { '@@redux-saga/IO': true,
        CALL:
         { context: null,
           fn:
            { [Function: sagaWrapper] '@@redux-saga-test-plan/saga-wrapper': true },
           args: [ Object [Generator] {}, [Function: refineYieldedValue] ] }     

另一方面,如果我将sagas代码从yield all({...})更改为:

const feedDocuments = yield __searchDocument(..);
cosnt tenantDocuments = yield __searchDocument(..);
const historicalDocuments = yield __searchDocument(..);

测试和模拟正常运行。

知道我在做什么错吗?为什么all似乎没有被正确嘲笑?

0 个答案:

没有答案