单元测试我的响应redux thunk时中间件不是函数错误

问题描述

我正在尝试测试我的thunk,因为它具有axios调用,所以我正在使用moxios来模拟axios调用。为了模拟存储和调度动作,我使用“ redux-mock-store”。但是,当我运行测试错误生成中间件不是函数”时,它还会显示“无法读取未定义的属性分派”,这意味着我的存储和分派没有被嘲笑,我无法找到原因这个问题。

Error shown in Terminal

下面是我写的代码

import {CONSTANTS} from '../constants'
import {EmployeeOnProjectData} from '../activeEmployee'
import expect from 'expect'
import moxios from 'moxios'
import configureMockStore from 'redux-mock-store'
const middleware=[thunk]
const mockStore=configureMockStore(middleware);

const initialState={
    active_employee_data:[]
}

const postsList = [
    {
      userId: 1,id: 1,title:
        "sunt aut facere repellat provident occaecati excepturi optio reprehenderit",body:
        "quia et suscipit suscipit recusandae consequuntur expedita et cum reprehenderit molestiae ut ut quas totam nostrum rerum est autem sunt rem eveniet architecto"
    }
  ];

  describe('to test the active employee in management thunk action',()=>{
  let store;
      beforeEach(()=>{
          moxios.install()
          store=mockStore(initialState)

      })
       afterEach(()=>{
           moxios.uninstall()
       })

    it('dispatched action correctly',()=>{
        moxios.wait(function(){
            let request = moxios.requests.mostRecent();

            request.respondWith({
                status: 200,response: [
                  {
                    userId: 1,title:
                      "sunt aut facere repellat provident occaecati excepturi optio reprehenderit",body:
                      "quia et suscipit suscipit recusandae consequuntur expedita et cum reprehenderit molestiae ut ut quas totam nostrum rerum est autem sunt rem eveniet architecto"
                  }
                ]
              });
            });
            const expectedActions = [
                {
                  type: CONSTANTS.ACTIVE_USER_SUCCESS,posts: postsList
                }
              ];
              return store.dispatch(EmployeeOnProjectData()).then(() => {
                const actualAction = store.getActions();
                expect(actualAction).toEqual(expectedActions);
                done();
              });
    })
  })

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)