From 4399622f41fe1f8109d9001c853a9d3778a29d98 Mon Sep 17 00:00:00 2001 From: Michael Kimberlin Date: Tue, 5 Nov 2024 13:18:14 -0600 Subject: [PATCH] Switched to vi.useFakeTimers() from spy --- web-ui/src/pages/AnniversaryReportPage.test.jsx | 10 ++++++---- web-ui/src/pages/BirthdayReportPage.test.jsx | 11 +++++++---- 2 files changed, 13 insertions(+), 8 deletions(-) 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(); });