From 3f072976fe2514b9a4dbb967f19f51e2ec920a28 Mon Sep 17 00:00:00 2001 From: alisaza Date: Sun, 13 Sep 2026 13:31:19 +0330 Subject: [PATCH] test(axios): refactor axios functional tests for improved clarity Refactored the axios functional tests by removing unnecessary asynchronous imports and simplifying the setup in the `beforeEach` hook. This change enhances the readability and maintainability of the test code, ensuring it aligns with the project's coding standards. --- config/axios.functional.test.ts | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/config/axios.functional.test.ts b/config/axios.functional.test.ts index 2d4f120..ef85952 100644 --- a/config/axios.functional.test.ts +++ b/config/axios.functional.test.ts @@ -1,6 +1,8 @@ import axios, { AxiosError, type InternalAxiosRequestConfig } from 'axios' import { beforeEach, describe, expect, it, vi } from 'vitest' +import axiosInstance, { getOrRefreshAccessToken, resetAxiosAuthModuleState } from '@/config/axios' + const mocks = vi.hoisted(() => ({ expireRefreshSession: vi.fn().mockResolvedValue(undefined), })) @@ -23,18 +25,15 @@ const writeStoredToken = (accessToken: string): void => { } describe('admin access-token refresh races', () => { - beforeEach(async () => { + beforeEach(() => { vi.clearAllMocks() vi.restoreAllMocks() window.localStorage.clear() - const { resetAxiosAuthModuleState } = await import('@/config/axios') - resetAxiosAuthModuleState() }) it('replays a late 401 with the newer stored token without rotating refresh again', async () => { writeStoredToken('access-a') - const { default: axiosInstance } = await import('@/config/axios') const refreshRequest = vi.spyOn(axios, 'post') const authorizationHeaders: string[] = [] let requestCount = 0 @@ -85,7 +84,6 @@ describe('admin access-token refresh races', () => { }) try { - const { getOrRefreshAccessToken } = await import('@/config/axios') const refreshRequest = vi.spyOn(axios, 'post') await expect(getOrRefreshAccessToken()).resolves.toBe('access-b')