From a62c0c1afc3bfda38bb02a0006eda72b2b69d47d Mon Sep 17 00:00:00 2001 From: Jake Howell Date: Tue, 21 Apr 2026 23:24:27 +1000 Subject: [PATCH] fix(site): fix flaky TemplateVariablesPage submit test (#24459) --- .../TemplateVariablesPage/TemplateVariablesPage.test.tsx | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/site/src/pages/TemplateSettingsPage/TemplateVariablesPage/TemplateVariablesPage.test.tsx b/site/src/pages/TemplateSettingsPage/TemplateVariablesPage/TemplateVariablesPage.test.tsx index 7b008226eb..02bee156da 100644 --- a/site/src/pages/TemplateSettingsPage/TemplateVariablesPage/TemplateVariablesPage.test.tsx +++ b/site/src/pages/TemplateSettingsPage/TemplateVariablesPage/TemplateVariablesPage.test.tsx @@ -62,7 +62,13 @@ describe("TemplateVariablesPage", () => { }); it("user submits the form successfully", async () => { - vi.spyOn(API, "getTemplateByName").mockResolvedValueOnce(MockTemplate); + // Use mockResolvedValue (not Once) because the + // updateActiveTemplateVersion mutation's onSuccess callback calls + // queryClient.invalidateQueries, which refetches this query. With + // mockResolvedValueOnce the refetch falls through to the real + // implementation (axios → MSW), adding non-deterministic latency + // that can push toast.success past the waitFor timeout under CI load. + vi.spyOn(API, "getTemplateByName").mockResolvedValue(MockTemplate); vi.spyOn(API, "getTemplateVersion").mockResolvedValue(MockTemplateVersion); vi.spyOn(API, "getTemplateVersionVariables").mockResolvedValueOnce([ MockTemplateVersionVariable1,