【问题标题】:How do I get the dev tools of redux to work with jest and enzymes如何让 redux 的开发工具与 jest 和酶一起使用
【发布时间】:2020-03-23 11:23:41
【问题描述】:

你好,请帮忙。

为什么我的测试会因这个 redux 存储设置而中断。

如果我注释掉 redux 开发工具,它可以工作吗?

    // window.__REDUX_DEVTOOLS_EXTENSION__ && window.__REDUX_DEVTOOLS_EXTENSION__()
import React from 'react'
import { Provider } from 'react-redux'
import { createStore, compose, applyMiddleware } from 'redux'
import reducers from './Reducers'
import reduxPromise from 'redux-promise'

const store = (initialState) => createStore(
  reducers,
  initialState,
  compose(
    applyMiddleware(
      reduxPromise
    ),
    window.__REDUX_DEVTOOLS_EXTENSION__ && window.__REDUX_DEVTOOLS_EXTENSION__()
  )
);

export default ({children, initialState ={}}) => (
  <Provider store={store(initialState)}>
    {children}
  </Provider>
);

谢谢

【问题讨论】:

    标签: reactjs testing redux jestjs enzyme


    【解决方案1】:

    这是给我的答案,它有效

    import React from 'react'
    import { Provider } from 'react-redux'
    import { createStore, compose, applyMiddleware } from 'redux'
    import reducers from './Reducers'
    import reduxPromise from 'redux-promise'
    
    const store = (initialState) => {
      const composeEnhancers =
        window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__ || compose;
    
      return createStore(
        reducers,
        initialState,
        composeEnhancers(applyMiddleware(reduxPromise))
      )
    };
    
    export default ({ children, initialState = {} }) => (
      <Provider store={store(initialState)}>
        {children}
      </Provider>
    );
    
    
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-06-07
      • 1970-01-01
      • 2017-07-19
      • 1970-01-01
      • 2016-12-15
      • 1970-01-01
      • 2017-07-08
      • 2021-11-22
      相关资源
      最近更新 更多