X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/1efba8f3b728a3b8aa3c64c5aa09f441318ff2a8..4a9e5c926179b3ab8ff7231904e2db93d42149e0:/services/workbench2/src/views-components/auto-logout/auto-logout.test.tsx

diff --git a/services/workbench2/src/views-components/auto-logout/auto-logout.test.tsx b/services/workbench2/src/views-components/auto-logout/auto-logout.test.tsx
index c9b9e2b83f..b07e3dccfa 100644
--- a/services/workbench2/src/views-components/auto-logout/auto-logout.test.tsx
+++ b/services/workbench2/src/views-components/auto-logout/auto-logout.test.tsx
@@ -14,15 +14,12 @@ describe('<AutoLogoutComponent />', () => {
     const sessionIdleTimeout = 300;
     const lastWarningDuration = 60;
     const eventListeners = {};
-    jest.useFakeTimers();
 
-    beforeAll(() => {
+    beforeEach(() => {
+        jest.useFakeTimers();
         window.addEventListener = jest.fn((event, cb) => {
             eventListeners[event] = cb;
         });
-    });
-
-    beforeEach(() => {
         props = {
             sessionIdleTimeout: sessionIdleTimeout,
             lastWarningDuration: lastWarningDuration,
@@ -34,28 +31,28 @@ describe('<AutoLogoutComponent />', () => {
     });
 
     it('should logout after idle timeout', () => {
-        jest.runTimersToTime((sessionIdleTimeout-1)*1000);
+        jest.advanceTimersByTime((sessionIdleTimeout-1)*1000);
         expect(props.doLogout).not.toBeCalled();
-        jest.runTimersToTime(1*1000);
+        jest.advanceTimersByTime(1*1000);
         expect(props.doLogout).toBeCalled();
     });
 
     it('should warn the user previous to close the session', () => {
-        jest.runTimersToTime((sessionIdleTimeout-lastWarningDuration-1)*1000);
+        jest.advanceTimersByTime((sessionIdleTimeout-lastWarningDuration-1)*1000);
         expect(props.doWarn).not.toBeCalled();
-        jest.runTimersToTime(1*1000);
+        jest.advanceTimersByTime(1*1000);
         expect(props.doWarn).toBeCalled();
     });
 
     it('should reset the idle timer when activity event is received', () => {
-        jest.runTimersToTime((sessionIdleTimeout-lastWarningDuration-1)*1000);
+        jest.advanceTimersByTime((sessionIdleTimeout-lastWarningDuration-1)*1000);
         expect(props.doWarn).not.toBeCalled();
         // Simulate activity from other window/tab
         eventListeners.storage({
             key: LAST_ACTIVE_TIMESTAMP,
             newValue: '42' // value currently doesn't matter
         })
-        jest.runTimersToTime(1*1000);
+        jest.advanceTimersByTime(1*1000);
         // Warning should not appear because idle timer was reset
         expect(props.doWarn).not.toBeCalled();
     });
