diff --git a/test/moves/parting-shot.test.ts b/test/moves/parting-shot.test.ts index ac7f26f5563..b3ba2c29718 100644 --- a/test/moves/parting-shot.test.ts +++ b/test/moves/parting-shot.test.ts @@ -73,31 +73,9 @@ describe("Moves - Parting Shot", () => { SpeciesId.ABRA, ]); - // use Memento 3 times to debuff enemy - game.move.select(MoveId.MEMENTO); - await game.phaseInterceptor.to("FaintPhase"); - expect(game.scene.getPlayerParty()[0].isFainted()).toBe(true); - game.doSelectPartyPokemon(1); - - await game.phaseInterceptor.to("TurnInitPhase", false); - game.move.select(MoveId.MEMENTO); - await game.phaseInterceptor.to("FaintPhase"); - expect(game.scene.getPlayerParty()[0].isFainted()).toBe(true); - game.doSelectPartyPokemon(2); - - await game.phaseInterceptor.to("TurnInitPhase", false); - game.move.select(MoveId.MEMENTO); - await game.phaseInterceptor.to("FaintPhase"); - expect(game.scene.getPlayerParty()[0].isFainted()).toBe(true); - game.doSelectPartyPokemon(3); - - // set up done - await game.phaseInterceptor.to(TurnInitPhase, false); const enemyPokemon = game.field.getEnemyPokemon(); - expect(enemyPokemon).toBeDefined(); - - expect(enemyPokemon.getStatStage(Stat.ATK)).toBe(-6); - expect(enemyPokemon.getStatStage(Stat.SPATK)).toBe(-6); + enemyPokemon.setStatStage(Stat.ATK, -6); + enemyPokemon.setStatStage(Stat.SPATK, -6); // now parting shot should fail game.move.select(MoveId.PARTING_SHOT); diff --git a/test/test-utils/helpers/prompt-handler.ts b/test/test-utils/helpers/prompt-handler.ts index 48b30064724..989c09ff4be 100644 --- a/test/test-utils/helpers/prompt-handler.ts +++ b/test/test-utils/helpers/prompt-handler.ts @@ -61,6 +61,9 @@ export class PromptHandler extends GameManagerHelper { ).mockImplementation((...args) => this.setMode(args)); // Set an interval to repeatedly check the current prompt. + if (PromptHandler.runInterval) { + throw new Error("Prompt handler run interval was not properly cleared on test end!"); + } PromptHandler.runInterval = setInterval(() => this.doPromptCheck()); } @@ -94,7 +97,6 @@ export class PromptHandler extends GameManagerHelper { } const prompt = this.prompts[0]; - this.doLog("Checking prompts..."); // remove expired prompts if (prompt.expireFn?.()) { diff --git a/test/test-utils/phase-interceptor.ts b/test/test-utils/phase-interceptor.ts index 7a221256af5..fb7e2329f38 100644 --- a/test/test-utils/phase-interceptor.ts +++ b/test/test-utils/phase-interceptor.ts @@ -74,15 +74,17 @@ export class PhaseInterceptor { // TODO: remove bangs once signature is updated let currentPhase: Phase = pm.getCurrentPhase()!; + let didLog = false; + // NB: This has to use an interval to wait for UI prompts to activate. // TODO: Rework after UI rework await vi.waitUntil( async () => { // If we were interrupted by a UI prompt, we assume that the calling code will queue inputs to // end the current phase manually, so we just wait for the phase to end from the caller. - if (this.state === "interrupted") { + if (this.state === "interrupted" && !didLog) { this.doLog("PhaseInterceptor.to: Waiting for phase to end after being interrupted!"); - await setTimeout(50); + didLog = true; return false; } diff --git a/test/test-utils/tests/helpers/prompt-handler.test.ts b/test/test-utils/tests/helpers/prompt-handler.test.ts index 4caa1feb2a8..2b313406cdb 100644 --- a/test/test-utils/tests/helpers/prompt-handler.test.ts +++ b/test/test-utils/tests/helpers/prompt-handler.test.ts @@ -8,7 +8,7 @@ import type { PhaseInterceptor } from "#test/test-utils/phase-interceptor"; import type { UI } from "#ui/ui"; import { beforeAll, beforeEach, describe, expect, it, type Mock, vi } from "vitest"; -describe("Utils - PromptHandler", () => { +describe("Test Utils - PromptHandler", () => { let promptHandler: PromptHandler; let handler: AwaitableUiHandler; diff --git a/test/test-utils/tests/phase-interceptor/integration.test.ts b/test/test-utils/tests/phase-interceptor/integration.test.ts index 90b7f2d9e22..4e381668001 100644 --- a/test/test-utils/tests/phase-interceptor/integration.test.ts +++ b/test/test-utils/tests/phase-interceptor/integration.test.ts @@ -52,7 +52,7 @@ describe("Utils - Phase Interceptor - Integration", () => { it("should not break when phase ended early via prompt", async () => { await game.classicMode.startBattle([SpeciesId.REGIELEKI]); - game.onNextPrompt("CommandPhase", UiMode.FIGHT, () => { + game.onNextPrompt("CommandPhase", UiMode.COMMAND, () => { game.endPhase(); }); diff --git a/test/vitest.setup.ts b/test/vitest.setup.ts index f6d1755fcd2..bea36b56e5c 100644 --- a/test/vitest.setup.ts +++ b/test/vitest.setup.ts @@ -60,14 +60,17 @@ afterAll(() => { afterEach(() => { clearInterval(PromptHandler.runInterval); + PromptHandler.runInterval = undefined; }); process.on("uncaughtException", err => { clearInterval(PromptHandler.runInterval); + PromptHandler.runInterval = undefined; throw err; }); process.on("unhandledRejection", err => { clearInterval(PromptHandler.runInterval); + PromptHandler.runInterval = undefined; throw err; });