【发布时间】:2021-09-20 09:30:38
【问题描述】:
我有一个生成器,我想用单元测试来介绍
export default function* gatawayFlow() {
yield all([
takeEvery(actionTypes.GET_GATEWAYS_REQUEST, getGatewaysFlow),
takeLatest(actionTypes.SELECT_GATEWAY_REQUEST, selectGatewayFlow),
]);
}
我用 redux-sag-test-plan 写了一个简单的测试
import {expectSaga, testSaga} from 'redux-saga-test-plan';
import gatawayFlow, {getGatewaysFlow, selectGatewayFlow} from '../logic/sagas';
import * as actions from '../logic/actions';
import * as actionTypes from '../logic/actionTypes';
import {takeEvery, takeLatest} from '@redux-saga/core/effects';
// Unit-test
describe('Unit tests', () => {
test('Test all effect', () => {
const saga = testSaga(gatawayFlow);
saga
.next()
.all({
[actionTypes.GET_GATEWAYS_REQUEST]: takeEvery(actionTypes.GET_GATEWAYS_REQUEST, getGatewaysFlow),
[actionTypes.SELECT_GATEWAY_REQUEST]: takeLatest(actionTypes.SELECT_GATEWAY_REQUEST, selectGatewayFlow)
})
.next()
.isDone();
// expect(gatawayFlow().next().value).toEqual(all([
// takeEvery(actionTypes.GET_GATEWAYS_REQUEST, getGatewaysFlow),
// takeEvery(actionTypes.SELECT_GATEWAY_REQUEST, selectGatewayFlow),
// ])); ---> THIS TEST WORKS CORRECT
});
});
我的测试没有通过。我的终端出现此错误。有什么想法可以解决吗?
【问题讨论】:
标签: javascript unit-testing redux redux-saga redux-saga-test-plan