Reactjs React测试呈现调用组件方法
我有以下组成部分:Reactjs React测试呈现调用组件方法,reactjs,react-test-renderer,Reactjs,React Test Renderer,我有以下组成部分: export const FormikInput: React.SFC<Props> = (props: Props) => { const handleChange = (value: string) => { // do something props.setFieldValue(props.key, value); return ( <TextField
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]}
/>
);
export const FormikInput:React.SFC=(props:props)=>{
常量handleChange=(值:字符串)=>{
//做点什么
props.setFieldValue(props.key,value);
返回(
);
})
我想调用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();
});
});
description('handleChange事件成功',()=>{
它('handleChange调用时不抛出错误',()=>{
const handleChange=jest.fn();
常量包装器=浅();
find('.myTextField').simulate('change');
期望(handleChange).tohavebeincall();
});
});
您的TS可能需要一些调整,我为JS编写了这篇文章。listen react test render用于快照测试。如果您正在进行组件行为测试,那么您应该进行浅层渲染并模拟句柄更改函数。是的,我想测试我的handlechange函数的行为。您能给我一个示例吗?这是 酶
,问题是关于反应测试denderer