我有这个测试:
import { expectSaga } from 'redux-saga-test-plan';
import { watchFetchAllCompanies } from 'store/core/sagas';
import { select } from 'redux-saga/effects';
import { companySelectedSelector } from 'store/core/selectors';
import * as matchers from 'redux-saga-test-plan/matchers';
import * as actions from 'store/core/actions';
import * as services from 'store/core/services';
const fakeCompanySelected = {
icomp: '234234sdhsdfg',
};
const fakeAllCompanies = [
{
id: 0,
},
{
id: 1,
},
{
id: 2,
},
];
describe('Core sagas module: ', () => {
it('Should fail if store is empty: ', () =>
expectSaga(watchFetchAllCompanies)
.provide([
[select(companySelectedSelector), fakeCompanySelected],
[matchers.call.fn(services.fetchAllCompanies), fakeAllCompanies],
])
.put(actions.successGetAllCompanies(fakeAllCompanies))
.dispatch(actions.getAllCompanies)
.run());
});
但是,当我运行此测试时,出现此错误:
那是我的传奇!
function* workerFetchAllCompanies() {
const companySelected = yield select(companySelectedSelector);
try {
const { data } = yield call(services.fetchAllCompanies);
if (!companySelected) {
yield put(actions.setCompany(data[0]));
}
yield put(actions.successGetAllCompanies(data));
} catch (error) {
yield put(actions.failureGetAllCompanies(error));
}
}
这是我的观察者:
export function* watchFetchAllCompanies() {
yield takeLatest(types.ALL_COMPANIES_GET, workerFetchAllCompanies);
}
因此,我不知道此功能无法正常工作的原因。我已经阅读了文档,但没有得到。 是什么原因?
谢谢。