const ErrorSnackbar = () => { const handelePrimaryBtnClick = () => { window.location.reload() } return ( <div className = 'sample_class' onClick={handelePrimaryBtnClick}> Sample Code </div> )}开玩笑地说,当我单击 div 时,如何检查是否调用了 window.location.reload()。
1 回答

MMMHUHU
TA贡献1834条经验 获得超8个赞
您可以窥探该reload方法并模拟单击div,例如:
it("should reload the page", () => {
jest.spyOn(window.location, 'reload');
const component = mount(ErrorSnackbar());
component.find('.sample_class').simulate('click');
expect(window.location.reload).toHaveBeenCalled();
});
添加回答
举报
0/150
提交
取消