From d5d63aa9791a2242cb2a29b507a3a246df1c0606 Mon Sep 17 00:00:00 2001 From: jubnl Date: Thu, 16 Apr 2026 16:01:06 +0200 Subject: [PATCH] test(journey): fix FE-PAGE-JOURNEYDETAIL-027 flaky spinner assertion Pre-seed the store into loading state before render instead of relying on timing. RTL's render() flushes all microtasks via act(), so the MSW response lands before render() returns, leaving no observable loading window. --- client/src/pages/JourneyDetailPage.test.tsx | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/client/src/pages/JourneyDetailPage.test.tsx b/client/src/pages/JourneyDetailPage.test.tsx index 3cd44406..4b7aad9d 100644 --- a/client/src/pages/JourneyDetailPage.test.tsx +++ b/client/src/pages/JourneyDetailPage.test.tsx @@ -674,7 +674,10 @@ describe('JourneyDetailPage', () => { // ── FE-PAGE-JOURNEYDETAIL-027 ────────────────────────────────────────── describe('FE-PAGE-JOURNEYDETAIL-027: Shows loading spinner before data loads', () => { it('renders a spinner while journey data is loading', () => { - // Do NOT await the waitFor -- we check the loading state before data arrives + // Pre-seed the store into a loading state (current: null, loading: true). + // We can't rely on render() timing because RTL wraps in act(), which flushes + // all microtasks including the MSW response before render() returns. + useJourneyStore.setState({ loading: true, current: null }); render(); // The spinner has animate-spin class on a div const spinner = document.querySelector('.animate-spin');