diff --git a/web-ui/src/pages/AnniversaryReportPage.test.jsx b/web-ui/src/pages/AnniversaryReportPage.test.jsx index 3258d10aaf..15a2448af7 100644 --- a/web-ui/src/pages/AnniversaryReportPage.test.jsx +++ b/web-ui/src/pages/AnniversaryReportPage.test.jsx @@ -14,7 +14,8 @@ const userStateWithPermission = { it('renders correctly', () => { const mockDate = new Date(2022, 1, 1); - const spy = vi.spyOn(global, 'Date').mockImplementation(() => mockDate); + vi.useFakeTimers(); + vi.setSystemTime(mockDate); snapshot( @@ -22,12 +23,13 @@ it('renders correctly', () => { ); - spy.mockRestore(); + vi.useRealTimers(); }); it('renders an error if user does not have appropriate permission', () => { const mockDate = new Date(2022, 1, 1); - const spy = vi.spyOn(global, 'Date').mockImplementation(() => mockDate); + vi.useFakeTimers(); + vi.setSystemTime(mockDate); snapshot( @@ -35,5 +37,5 @@ it('renders an error if user does not have appropriate permission', () => { ); - spy.mockRestore(); + vi.useRealTimers(); }); diff --git a/web-ui/src/pages/BirthdayReportPage.test.jsx b/web-ui/src/pages/BirthdayReportPage.test.jsx index fe744817f8..f70cfbdc06 100644 --- a/web-ui/src/pages/BirthdayReportPage.test.jsx +++ b/web-ui/src/pages/BirthdayReportPage.test.jsx @@ -1,4 +1,5 @@ import React from 'react'; +import { vi } from 'vitest'; import BirthdayReportPage from './BirthdayReportPage'; import { AppContextProvider } from '../context/AppContext'; @@ -14,7 +15,8 @@ const userStateWithPermission = { it('renders correctly', () => { const mockDate = new Date(2022, 1, 1); - const spy = vi.spyOn(global, 'Date').mockImplementation(() => mockDate); + vi.useFakeTimers(); + vi.setSystemTime(mockDate); snapshot( @@ -22,12 +24,13 @@ it('renders correctly', () => { ); - spy.mockRestore(); + vi.useRealTimers(); }); it('renders an error if user does not have appropriate permission', () => { const mockDate = new Date(2022, 1, 1); - const spy = vi.spyOn(global, 'Date').mockImplementation(() => mockDate); + vi.useFakeTimers(); + vi.setSystemTime(mockDate); snapshot( @@ -35,5 +38,5 @@ it('renders an error if user does not have appropriate permission', () => { ); - spy.mockRestore(); + vi.useRealTimers(); });