为click事件运行以下测试时,测试通过了,但是当我运行npm coverage
时,数字不变。知道为什么吗?首先是模态。
让我知道是否也需要发布batchUpdate
方法。
使用Jest酶-REACT JS
it("should call click event props on batchUpdate method", () => {
beforeEach(() => (wrapper = shallow(<Component {...baseProps} />)));
const FakeFun = jest.spyOn(wrapper.instance(), "batchUpdate");
wrapper.setState({
loadUpdatingSpinner: true,
selectedTo: "default"
});
wrapper.find("button").simulate("click");
wrapper.update();
expect(FakeFun).toHaveBeenCalled();
});
代码如下:
<Modal>
<button
className={
this.state.selectedTo === "default"
? "tran-button export-selected gray"
: "tran-button export-selected"
}
disabled={this.state.selectedTo === "default" ? true : false}
id="batchUpdate-secondclick"
onClick={() => {
this.batchUpdate();
}}
>
{this.state.loadUpdatingSpinner ? "Updating..." : "Update"}
</button>
</Modal>