我正在尝试按照文档使用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()
})
})问题是,我得到以下错误:
减速机先前接收的状态是意外类型的。预期参数为具有下列属性的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容器>呈现而不崩溃 TypeError: state.get不是一个函数
发布于 2020-06-15 12:46:03
您应该装入封装在Provider中的组件。
import { Provider } from 'react-redux'
// ...store configuration
const tree = Enzyme.mount(
<Provider store={store}>
<App />
<Provider>
)
// ... assertionsshallow还有第二个用于传递上下文的参数,但我不确定它是否是with。
https://stackoverflow.com/questions/51176472
复制相似问题