Javascript 无法初始化Redux模拟存储

Javascript 无法初始化Redux模拟存储,javascript,unit-testing,redux,mocking,redux-mock-store,Javascript,Unit Testing,Redux,Mocking,Redux Mock Store,我正试图按照文档使用redux模拟商店 import React from 'react' import Enzyme from 'enzyme' import Adapter from 'enzyme-adapter-react-16' import configureStore from 'redux-mock-store' import App from '.' import rootReducer from '../../store/reducers' Enzyme.configur

我正试图按照文档使用
redux模拟商店

import React from 'react'
import Enzyme from 'enzyme'
import Adapter from 'enzyme-adapter-react-16'
import configureStore from 'redux-mock-store'

import App from '.'
import rootReducer from '../../store/reducers'

Enzyme.configure({ adapter: new Adapter() })

describe('The App container', () => {
    let store
    const mockStore = configureStore()

    beforeEach(() => store = mockStore(rootReducer))

    it('renders without crashing', () => {
        const tree = Enzyme.shallow(<App store={store} />)
        expect(tree).toMatchSnapshot()
    })
})
● 应用程序容器›在不崩溃的情况下进行渲染

TypeError:state.get不是函数


您应该装入封装在
提供程序中的组件

import { Provider } from 'react-redux'

// ...store configuration

const tree = Enzyme.mount(
  <Provider store={store}>
    <App />
  <Provider>
)

// ... assertions
从'react redux'导入{Provider}
//…存储配置
const tree=Enzyme.mount(
)
// ... 断言

shallow
还有第二个参数用于传递上下文,但我不确定它是否与redux store一起工作。

查看文档,您不应该以initialState而不是rootReducer传递吗?或者某种对象?是的,当我尝试使用initialState时,我得到了
store.getState不是一个函数
很遗憾我没有创建沙盒链接。我不知道这是否能解决我的问题
import { Provider } from 'react-redux'

// ...store configuration

const tree = Enzyme.mount(
  <Provider store={store}>
    <App />
  <Provider>
)

// ... assertions