我正在用酶进行测试,但不知道如何模拟作为道具传递的功能。
it("should do not login when submit a user that not exist", () => {
const mock = jest.fn(() => true);
const wrapper = shallow(<HomeFormComponent form={{getFieldDecorator: () => mock()}}/>);
wrapper.find(Form).simulate("submit", {
preventDefault: () => {},
});
console.log(wrapper)
});
一个错误。
TypeError: getFieldDecorator(...) is not a function
在我的index.js中
render() {
const { getFieldDecorator } = this.props.form;
}
return (<FormItemContainer>
{getFieldDecorator("password", {
rules: [
{ required: true, message: "Please input your Password!" }
]
})(
<Input
prefix={
<Icon type="lock" style={{ color: "rgba(0,0,0,.25)" }} />
}
type="password"
placeholder="Password"
/>
)}
</FormItemContainer>)
答案 0 :(得分:0)
这行得通吗?
const mock = jest.fn();
const wrapper = shallow(<HomeFormComponent form={{getFieldDecorator: mock}}/>);