Reactjs 酶只对低水平的成分起作用吗?
我正在为React/Redux/Grommet应用程序编写一些单元测试。对于测试,我使用Jest/Enzyme/Chai/Sinon 我有以下组成部分:Reactjs 酶只对低水平的成分起作用吗?,reactjs,sinon,chai,enzyme,grommet,Reactjs,Sinon,Chai,Enzyme,Grommet,我正在为React/Redux/Grommet应用程序编写一些单元测试。对于测试,我使用Jest/Enzyme/Chai/Sinon 我有以下组成部分: import React from 'react' import FormField from 'grommet/components/FormField' import Box from 'grommet/components/Box' import Label from 'grommet/components/Label' import T
import React from 'react'
import FormField from 'grommet/components/FormField'
import Box from 'grommet/components/Box'
import Label from 'grommet/components/Label'
import TextInput from 'grommet/components/TextInput'
const CustomTextInput = ({label, value, onChange}) =>
<FormField label={<Label size='small'>{label}</Label>}>
<Box pad={{'horizontal': 'medium'}}>
<TextInput placeholder='Please Enter' value={value}
onDOMChange={event => onChange(event.target.value)}
/>
</Box>
</FormField>
export default CustomTextInput
我试着用两种不同的方法模拟onChange函数,主要是从和中获取想法。i、 e
我开始怀疑酶的
simulate
方法是否与更高级别的库组件(如grommet中的组件)交互有问题,或者是否需要直接应用于较低级别的
标记。有人经历过这种情况吗?grommet TextInput只是标准输入表单字段上的一个包装器,请尝试以下操作:
wrapper.find('input').simulate('change', {target: { value: 'a'}});
我希望我的回答能对你有所帮助
AssertionError: expected false to equal true
wrapper.find(TextInput).value = 'test'
wrapper.find(TextInput).simulate('change', {target: {value: 'test'}})
wrapper.find(TextInput).first().simulate('change', {target: {value: 'test'}})
wrapper.find('input').simulate('change', {target: { value: 'a'}});