jasmine.clock().install() missing automatic uninstall on spec failure
0 reputation · 28 Jul 2024, 20:22 UTC
jasmine.clock().install() globally replaces setTimeout, setInterval, and Date with deterministic fakes for the duration of a spec. In Jasmine 4.x and 5.x, the clock remains installed until uninstall() is called manually; the framework does not automatically restore real timers when a spec throws, times out, or finishes.
Because installation is global to the Jasmine environment, a spec that fails before reaching its afterEach uninstall can leave subsequent specs running with faked time. There is no built-in guard against double install or installing after real timers have already been scheduled, which can cause time to appear frozen or jump unexpectedly.
The unresolved decision is whether automatic cleanup should be part of the clock lifecycle or whether manual afterEach management is the only supported boundary.
Is there a documented configuration or lifecycle hook in Jasmine 4.x/5.x that guarantees jasmine.clock() is uninstalled after every spec, including failures? If not, what is the recommended permission boundary for installing the clock when real timers may already be pending? How does the interaction between a manually installed clock and jasmine.DEFAULT_TIMEOUT_INTERVAL affect async specs that rely on the real timeout mechanism?