反应酶减速器测试,TypeError: (0 , _PlanReducer.default) is not a function

时间:2021-05-03 09:36:54

标签: reactjs unit-testing react-redux jestjs enzyme

试图测试我的 reducer 是返回值还是不使用简单的测试用例,但得到的错误表明它不是一个函数。编写代码和下面的确切错误

describe('Plan Reducer', ()=>{
    it('Should return default state', () => {
        const newState = PlanReducer(undefined,{});
        expect(newState).toEqual([]);
    });

    it('Should return new state if recieving type', () => {
        const plans = [{title: 'Plan 1'}, {title: 'Plan 2'}];
        const newState = PlanReducer(undefined, {
            type: constant.FETCH_ALL_PLANS,
            payload: plans
        })
        expect(newState).toEqual(plans)
    })

但收到错误提示 TypeError: (0 , _PlanReducer.default) is not a function 这是我的减速器设置:

const initialState = {
    plans:[],
    planHistory:null,
    currentplan:null,
    transactions:[]
   };
   
   export const PlanReducer = (state = initialState, action) => {
     switch (action.type) {
      case constant.FETCH_ALL_PLANS:
        return {
            ...state,
            plans: [...action.payload.plansData]
        };
      case constant.CURRENT_PLAN:
        console.log(action.payload)
        return {
            ...state,
            currentplan: action.payload.currentsubscriptions[0],
            planHistory: action.payload.subscriptions
        };
      case constant.FETCH_TRANSACTION:
        console.log(action.payload)
        return {
            ...state,
            transactions: [...action.payload.transaction]
          };
         //default
       default:
         return state;
     }
   }

0 个答案:

没有答案