beforeAll(() => { jest.useFakeTimers(); jest.spyOn(global, 'setTimeout'); document.body.innerHTML = `

Your session will end soon. Please choose to extend your session or sign out. Your session will expire in 5 minutes or less.

You have been inactive for too long. Your session will expire in .

` const sessionTimerModule = require('../../app/assets/javascripts/timeoutPopup.js'); window.GOVUK.modules.start(); }); afterAll(() => { jest.useRealTimers(); document.body.innerHTML = ''; }); describe('When an authenticated user', () => { test('does whatever', () => { jest.runAllTimers(); }); }); describe('The session timer ', () => { test('logoutUser method logs the user out', () => { const logoutUserMethod = window.GOVUK.Modules.TimeoutPopup.logoutUser; expect(window.location.href).toEqual(expect.not.stringContaining('/sign-out')); logoutUserMethod(); expect(window.location.href).toEqual(expect.stringContaining('/sign-out')); }); test('extendSession method reloads the page', () => { const windowReload = jest.spyOn(window.location, 'reload'); const extendSessionMethod = window.GOVUK.Modules.TimeoutPopup.extendSession; extendSessionMethod(); expect(windowReload).toHaveBeenCalled(); }); test('showTimer method shows the session timer modal', () => { const sessionTimer = document.getElementById("sessionTimer"); sessionTimer.showModal = jest.fn(); const showTimerMock = jest.spyOn(sessionTimer, 'showModal'); window.GOVUK.Modules.TimeoutPopup.showTimer(); expect(showTimerMock).toHaveBeenCalled(); }); test('closeTimer method closes the session timer modal', () => { const sessionTimer = document.getElementById("sessionTimer"); sessionTimer.close = jest.fn(); const closeTimerMock = jest.spyOn(sessionTimer, 'close'); window.GOVUK.Modules.TimeoutPopup.closeTimer(); expect(closeTimerMock).toHaveBeenCalled(); }); });