【发布时间】:2018-10-23 17:30:54
【问题描述】:
我知道在simulate 我们通常可以这样做:
simulate("change", { target: { value: '7' } });
但是如果我的onChange 函数接受一个对象作为参数,我应该在第二个参数中传递什么?
interface myObject{
firstname: string;
lastname: string;
}
myChangeFunction(item: myObject) {
/* */
}
请注意我试过了:
const updates = { firstname: "john", lastname: "doe" };
simulate("change", { target: updates });
and
simulate("change", updates );
但它失败了。
【问题讨论】:
-
能否分享一下“change”事件函数的实现。
-
它只是用
item.firstname更新另一个状态属性。为了简洁起见,我把它省略了。
标签: javascript reactjs typescript jestjs enzyme