如何使用玩笑嘲笑自定义中间件并反应测试库?

时间:2019-05-13 06:22:08

标签: javascript reactjs testing react-testing-library

我正在使用redux中间件和反应测试库,并且遇到一个错误(仅在运行测试时): Actions must be plain objects. Use custom middleware for async actions.

所以我决定像这样将Redux中间件传递给我的测试:

const middlewares = [thunk, api]

renderWithRedux = (ui, { initialState, store = createStore(reducers, initialState, composeEnhancers(applyMiddleware(...middlewares))) } = {}) => {
            return {
                ...render(
                    <Provider store={store}>
                        {ui}
                    </Provider>,
                ),
                store,
            }
        }

但是现在我得到一个错误,我的中间件中的操作未定义。我想知道是否有一种特定的方法来模拟自定义中间件,因为我目前不打算对此进行测试,我正在尝试测试我的一个组件及其交互方式,因此我需要模拟一些针对该组件的操作那要发生

0 个答案:

没有答案