diff --git a/locust/webui/src/components/LineChart/LineChart.test.tsx b/locust/webui/src/components/LineChart/LineChart.test.tsx index 5153e904ae..a8d5a059e8 100644 --- a/locust/webui/src/components/LineChart/LineChart.test.tsx +++ b/locust/webui/src/components/LineChart/LineChart.test.tsx @@ -1,7 +1,7 @@ import { describe, test, expect } from 'vitest'; import LineChart from 'components/LineChart/LineChart'; -import { getStatsResponseTransformed } from 'test/mocks/statsRequest.mock'; +import { statsResponseTransformed } from 'test/mocks/statsRequest.mock'; import { renderWithProvider } from 'test/testUtils'; import { ICharts } from 'types/ui.types'; @@ -18,7 +18,7 @@ describe('LineChart', () => { test('renders LineChart with charts and lines', () => { const { container } = renderWithProvider( { afterAll(() => server.close()); test('should fetch request stats, ratios, and exceptions and update UI accordingly', async () => { - const { store } = renderWithProvider(); + act(async () => { + vi.useFakeTimers(); - await waitFor(() => { - expect(store.getState().ui).toEqual(getStatsResponseTransformed()); + vi.setSystemTime(mockDate); + + const { store } = renderWithProvider(); + + await vi.runAllTimersAsync(); + + expect(store.getState().ui).toEqual(statsResponseTransformed); + + vi.useRealTimers(); }); }); diff --git a/locust/webui/src/test/mocks/statsRequest.mock.ts b/locust/webui/src/test/mocks/statsRequest.mock.ts index b0623467ae..8a3c0ba003 100644 --- a/locust/webui/src/test/mocks/statsRequest.mock.ts +++ b/locust/webui/src/test/mocks/statsRequest.mock.ts @@ -97,7 +97,9 @@ export const exceptionsResponseMock = { ], }; -export const getStatsResponseTransformed = () => ({ +export const mockDate = new Date(1970, 1); + +export const statsResponseTransformed = { totalRps: 1932.5, failRatio: 100, stats: [ @@ -151,7 +153,7 @@ export const getStatsResponseTransformed = () => ({ currentFailPerSec: [1932.5], userCount: [1], totalAvgResponseTime: [0.41], - time: [new Date().toLocaleTimeString()], + time: [mockDate.toLocaleTimeString()], }, ratios: { perClass: { @@ -169,4 +171,4 @@ export const getStatsResponseTransformed = () => ({ }, userCount: 1, workers: undefined, -}); +};