Skip to content

AutoGPT is the vision of accessible AI for everyone, to use and to build on. Our mission is to provide the tools, so that you can focus on what matters.

fix(frontend): stop the expert-kickoff tests inheriting a stale kickoff latch (#14641)

Reinier van der Leere3b99ef844b4
diff --git a/autogpt_platform/frontend/src/app/(platform)/copilot/__tests__/expert-kickoff.test.tsx b/autogpt_platform/frontend/src/app/(platform)/copilot/__tests__/expert-kickoff.test.tsx
index ce2e24722e..e08e3d49ac 100644
--- a/autogpt_platform/frontend/src/app/(platform)/copilot/__tests__/expert-kickoff.test.tsx
+++ b/autogpt_platform/frontend/src/app/(platform)/copilot/__tests__/expert-kickoff.test.tsx
@@ -11,7 +11,7 @@ import { http, HttpResponse } from "msw";
import { parseAsString, useQueryState } from "nuqs";
import { withNuqsTestingAdapter } from "nuqs/adapters/testing";
import { useState } from "react";
-import { afterEach, describe, expect, it, vi } from "vitest";
+import { beforeEach, describe, expect, it, vi } from "vitest";
import { useCopilotStreamStore } from "../copilotStreamStore";
import {
buildKickoffMessage,
@@ -58,7 +58,10 @@ function latestKickoffAttemptToken(messages: UIMessage[]) {
return null;
}
-afterEach(() => {
+// Reset before the test, not after it: this file's `afterEach` runs BEFORE
+// testing-library's `cleanup`, so the previous test's tree is still mounted
+// when the kickoff latch is cleared and can write it straight back.
+beforeEach(() => {
server.resetHandlers();
sendSpy.mockReset();
flagState.values = { "hire-experts": true };