TypeError:无法读取Saga测试中未定义的属性”

时间:2018-10-18 09:04:23

标签: reactjs jasmine jestjs redux-saga

我正在对我的react代码使用jest进行测试,其中还包括sagas。 我所有的测试都通过了,但是我得到了一个有趣的console.error,如下所示。以下代码有什么错误?

这是运行测试时的控制台

console.error node_modules/redux-saga/lib/internal/utils.js:240
  uncaught at rootSaga at rootSaga 
   at rootSaga 
   TypeError: Cannot read property 'FETCH_ORDERS_REQUEST' of undefined
      at FETCH_ORDERS_REQUEST (..../redux/sagas.js:38:25)
      at Object.<anonymous>.exports.default.next (<anonymous>)
      at next (.../node_modules/redux-saga/lib/internal/proc.js:322:27)
      at proc (..../node_modules/redux-saga/lib/internal/proc.js:281:3)
      at resolveIterator (.../node_modules/redux-saga/lib/internal/proc.js:467:5)
      at runEffect (/.../node_modules/redux-saga/lib/internal/proc.js:443:178)

sagas.js:

import { call, put, takeEvery, all } from 'redux-saga/effects';
import * as loadboardAPI from 'api/loadboard';
import * as ordersAPI from 'api/orders';
import * as actions from './actions';
import * as types from './types';

export function* fetchOrders({ query }) {
    try {
        const response = yield call(loadboardAPI.searchOrders, adaptedQuery);
        const orders = response.data.objects;

        yield put(actions.fetchOrdersSuccess(orders));
    } catch (error) {
        yield put(actions.fetchOrdersFailure(error));
    }
}
...
        export default function*() {
        yield all([
            takeEvery(types.FETCH_ORDERS_REQUEST, fetchOrders),
            ....
        ]);
    }

sagas.test.js的部分失败

import { all, call, put, takeEvery } from 'redux-saga/effects';
import * as loadboardAPI from 'api/loadboard';
import * as actions from './actions';
import * as types from './types';
import * as sagas from './sagas';

describe('default', () => {
        const saga = sagas.default();
        const output = saga.next().value;
        const expected = all([
            takeEvery(types.FETCH_ORDERS_REQUEST, sagas.fetchOrders),
        ]);

        expect(output).toEqual(expected);
    });

0 个答案:

没有答案