From 09b4d38265e24f81d85ed3c938f9bae68bf7e3c2 Mon Sep 17 00:00:00 2001 From: shiva Date: Fri, 13 Dec 2024 18:43:38 +0530 Subject: [PATCH] refactor:vitest to Requests screen --- .github/workflows/compare_translations.py | 0 src/screens/Requests/Requests.spec.tsx | 18 ++++++++++++++++++ 2 files changed, 18 insertions(+) mode change 100644 => 100755 .github/workflows/compare_translations.py diff --git a/.github/workflows/compare_translations.py b/.github/workflows/compare_translations.py old mode 100644 new mode 100755 diff --git a/src/screens/Requests/Requests.spec.tsx b/src/screens/Requests/Requests.spec.tsx index 0be900404e..29c1fcf254 100644 --- a/src/screens/Requests/Requests.spec.tsx +++ b/src/screens/Requests/Requests.spec.tsx @@ -22,6 +22,14 @@ import { import useLocalStorage from 'utils/useLocalstorage'; import { vi } from 'vitest'; +/** + * Unit tests for the `Requests` screen. + * + */ +/** + * Set up `localStorage` stubs for testing. + */ + vi.stubGlobal('localStorage', { getItem: vi.fn(), setItem: vi.fn(), @@ -29,6 +37,9 @@ vi.stubGlobal('localStorage', { removeItem: vi.fn(), }); +/** + * Mock `window.location` for testing redirection behavior. + */ Object.defineProperty(window, 'location', { value: { href: 'http://localhost/', assign: vi.fn(), reload: vi.fn() }, }); @@ -43,6 +54,13 @@ const link5 = new StaticMockLink(MOCKS_WITH_ERROR, true); const link6 = new StaticMockLink(MOCKS3, true); const link7 = new StaticMockLink(MOCKS4, true); +/** + * Utility function to wait for a specified amount of time. + * Wraps `setTimeout` in an `act` block for testing purposes. + * + * @param ms - The duration to wait in milliseconds. Default is 100ms. + * @returns A promise that resolves after the specified time. + */ async function wait(ms = 100): Promise { await act(() => { return new Promise((resolve) => {