首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >模拟不使用trim()酶的变化

模拟不使用trim()酶的变化
EN

Stack Overflow用户
提问于 2019-09-02 13:36:52
回答 1查看 64关注 0票数 1

当我有一个错误时,我正在使用这个测试,所以我使用trim函数来解决它,这些测试失败了,尝试了不同的方法,但是没有找到解决方案。

代码语言:javascript
复制
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)
    })
})

代码语言:javascript
复制
onSearchChange (searchValue) {
    const value = searchValue.trim()
    this.setState({ searchValue: value, userInteractedWithComponent: true })
}

错误消息

TypeError: searchValue.trim不是一个函数

任何建议

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2019-09-02 13:49:00

您的函数将对象作为参数。公开您需要的字段

我看不出全貌,但我能猜到你需要这样的东西

代码语言:javascript
复制
onSearchChange ({ target: { value: incomeValue } }) {
    const value = incomeValue.trim()
    this.setState({ searchValue: value, userInteractedWithComponent: true })
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/57757926

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档