mirror of
https://github.com/prymitive/karma
synced 2026-05-13 03:56:59 +00:00
fix(ui): fix upgrade needed reload
This commit is contained in:
committed by
Łukasz Mierzwa
parent
06d8eb6089
commit
d15a0f1ff1
@@ -11,7 +11,8 @@ import "csshake/scss/csshake-slow.scss";
|
||||
|
||||
const UpgradeNeeded = ({ newVersion, reloadAfter }) => {
|
||||
useEffect(() => {
|
||||
setTimeout(window.location.reload, reloadAfter);
|
||||
const timer = setTimeout(() => window.location.reload(), reloadAfter);
|
||||
return () => clearTimeout(timer);
|
||||
}, [reloadAfter]);
|
||||
|
||||
return (
|
||||
|
||||
@@ -34,4 +34,16 @@ describe("<UpgradeNeeded />", () => {
|
||||
jest.runOnlyPendingTimers();
|
||||
expect(reloadSpy).toBeCalled();
|
||||
});
|
||||
|
||||
it("stops calling window.location.reload after unmount", () => {
|
||||
const reloadSpy = jest
|
||||
.spyOn(global.window.location, "reload")
|
||||
.mockImplementation(() => {});
|
||||
const tree = mount(
|
||||
<UpgradeNeeded newVersion="1.2.3" reloadAfter={100000000} />
|
||||
);
|
||||
tree.unmount();
|
||||
jest.runOnlyPendingTimers();
|
||||
expect(reloadSpy).not.toBeCalled();
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user