我正在尝试redux-mock-store
按照文档使用
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()
})
})
问题是,我收到以下错误:
reducer 接收到的先前状态是意外类型。预期参数是 Immutable.Collection 或 Immutable.Record 的实例,具有以下属性:
也:
TypeError: inputState.withMutations 不是函数
我不应该包括rootReducer
吗?
有没有更好的方法来初始化模拟商店?
编辑:我也试过用来initialState
开店,但不行:
import React from 'react'
import Enzyme from 'enzyme'
import Adapter from 'enzyme-adapter-react-16'
import configureStore from 'redux-mock-store'
import App from '.'
Enzyme.configure({ adapter: new Adapter() })
describe('The App container', () => {
let store
const mockStore = configureStore()
const initialState = {}
beforeEach(() => store = mockStore(initialState))
it('renders without crashing', () => {
const tree = Enzyme.shallow(<App store={store} />)
expect(tree).toMatchSnapshot()
})
})
● App 容器 › 渲染不崩溃
类型错误:state.get 不是函数