我具有以下组件:
export const FormikInput: React.SFC<Props> = (props: Props) => {
const handleChange = (value: string) => {
// do something
props.setFieldValue(props.key, value);
return (
<TextField
label={props.label}
onChangeText={handleChange}
value={props.values[props.key]}
/>
);
};
我想调用handleChange
方法的用户react-test-renderer
有可能吗?
答案 0 :(得分:0)
将classname
赋予TextField
并像这样模拟您的handleChange
:
describe('handleChange event success', () => {
it('handleChange invokes without throwing an error', () => {
const handleChange = jest.fn();
const wrapper = shallow(<YourComponent
handleChange ={handleChange}
/>);
wrapper.find('.myTextField').simulate('change');
expect(handleChange ).toHaveBeenCalled();
});
});
您的TS可能需要一些调整,我已经为JS编写了