【发布时间】:2019-04-22 10:23:19
【问题描述】:
我正在尝试使用redux-mock-store 在我的React 应用程序中测试一些异步代码。
const configureMockStore = require('redux-mock-store').default;
const thunk = require("redux-thunk").default;
const middlewares = [thunk];
const mockStore = configureMockStore(middlewares);
const dummy = () => {
// Mock Ajax call
return new Promise((resolve, reject) => {
setTimeout(() => resolve({data: 'data'}), 200)
})
};
describe("Redux Mock Store", () => {
it("Test Dummy Ajax call", () => {
const expectedActions = [
{ type: "SUCCESS", payload: "success" },
{ type: "FAILURE", error: { Error: "Error" } }
];
const store = mockStore({});
store.dispatch(dummy().then(() => {
expect(store.getActions()).toEqual(expectedActions)
}).catch(error => { console.log(error) }))
});
});
我正在使用Jest 运行此测试。在测试Actions must be plain objects. Use custom middleware for async actions.上面运行时出现以下错误@这里有什么问题?
【问题讨论】:
标签: javascript testing redux jestjs redux-mock-store