不太确定为什么无法找到该元素并传递Onclick事件。将Jest和Enzyme用于React JS
这是我到目前为止所做的
beforeEach(() => wrapper = shallow(<Component {...baseProps} />));
it("should call button click event on FINISH", () => {
baseProps.onClick.mockClear();
baseProps.closeModal.mockClear();
wrapper.setState({
INITIAL_STATE:{}
});
wrapper.update();
wrapper.find('#Finish-testclick').prop('onClick');
expect(baseProps.closeModal).toHaveBeenCalled();
});
也尝试了以下方法
wrapper.find('#Finish-testclick').simulate('click');
代码如下:
<Modal>
<button className={'tran-button export-selected'} id='Finish-testclick' onClick={() => {this.closeModal()}}>
Finish
</button>
</div>
}
</div>
</Modal>
关闭模态方法
closeModal = () => {
this.props.closeModal();
this.setState(INITIAL_STATE);
}