Skip to content

Commit 62ef166

Browse files
test(evm): add test for auto-reload after hardforks
1 parent 0244b0b commit 62ef166

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import { renderComponent } from 'testUtils/render';
2+
3+
import { ChainUpgradeHandler } from 'App/ChainUpgradeHandler';
4+
import type { MockInstance } from 'vitest';
5+
6+
const runtimeTimestamp = new Date().getTime();
7+
const upgradeTimestamps = [new Date(runtimeTimestamp + 2000)];
8+
const fakeNowMs = runtimeTimestamp + 12000;
9+
10+
describe('ChainUpgradeHandler', () => {
11+
let reloadSpy: MockInstance;
12+
13+
beforeEach(() => {
14+
// 1. Redefine the 'reload' property on window.location to be configurable.
15+
// This is necessary because it is non-configurable by default in jsdom.
16+
Object.defineProperty(window, 'location', {
17+
configurable: true,
18+
value: () => {}, // Provide a dummy function initially
19+
});
20+
21+
Object.defineProperty(window.location, 'reload', {
22+
configurable: true,
23+
value: () => {}, // Provide a dummy function initially
24+
});
25+
26+
// 2. Create the spy on the now-configurable property.
27+
reloadSpy = vi.spyOn(window.location, 'reload');
28+
});
29+
30+
it('auto reload after passing hardforks', () => {
31+
vi.useFakeTimers().setSystemTime(new Date(fakeNowMs));
32+
33+
renderComponent(<ChainUpgradeHandler upgradeTimestamps={upgradeTimestamps} />);
34+
35+
expect(reloadSpy).toHaveBeenCalled();
36+
});
37+
});

0 commit comments

Comments
 (0)