当我有一个错误时,我正在使用这个测试,所以我使用trim函数来解决它,这些测试失败了,尝试了不同的方法,但是没有找到解决方案。
const generalWrapper = shallow(<AddVehiclesTable {...generalProps} />)
const generalInstance = generalWrapper.instance()
describe('onSearchChange', () => {
test('should change the "search" state', () => {
const theFilterValue = 'a new filter value'
generalWrapper.find('.filter-input').simulate('change', { target: { value: theFilterValue } })
const expectedState = Object.assign({}, generalInstance.state)
expectedState.searchValue = { 'target': { 'value': theFilterValue } }
expect(generalInstance.state).toEqual(expectedState)
expect(generalInstance.state.userInteractedWithComponent).toBe(true)
})
})
onSearchChange (searchValue) {
const value = searchValue.trim()
this.setState({ searchValue: value, userInteractedWithComponent: true })
}
错误消息
TypeError: searchValue.trim不是一个函数
任何建议
发布于 2019-09-02 13:49:00
您的函数将对象作为参数。公开您需要的字段
我看不出全貌,但我能猜到你需要这样的东西
onSearchChange ({ target: { value: incomeValue } }) {
const value = incomeValue.trim()
this.setState({ searchValue: value, userInteractedWithComponent: true })
}https://stackoverflow.com/questions/57757926
复制相似问题