模拟存储在测试运行时抛出错误



这是我的测试文件

import React from 'react'
import { shallow } from 'enzyme'
import renderer from 'react-test-renderer'
import configureStore from 'redux-mock-store'
import Stock from '../Stock'
const initialState = {}
const mockStore = configureStore()
const store = mockStore(initialState)
test('tets for the onUpdate function', () => {
const props = {
setErrorPopUp: jest.fn(),
formSubmitAttempt: jest.fn()
}
const wrapper = shallow(<Stock {...props} store={store} />)
wrapper.instance().onUpdate({ quantity: 0 })
expect(props.setErrorPopUp).toHaveBeenCalled()
wrapper.instance().onUpdate({ quantity: 3 })
expect(props.formSubmitAttempt).toHaveBeenCalled()
}))

这在运行时抛出了一个错误。我无法调试错误需要一个人来解决这个问题

后出现错误

tets for the onUpdate function
TypeError: state.get is not a function
3 |  * Direct selector to the order state domain
4 |  */
> 5 | const selectStockDomain = state => state.get('chefStock')
6 | const selectAppDomain = state => state.get('app')
7 |

这个代码出了什么问题以及如何解决这个

您可能在存储中使用immutableJS来添加、获取和删除数据。

您可以使用immutableJS初始化您的商店

const initialState = fromJS({ key: 'val' })

你可以用一个伪get()函数初始化你的商店

const initialState = { get: () => {}}

相关内容

最新更新