pokerogue/src/test/utils/helpers/moveHelper.ts

36 lines
1.3 KiB
TypeScript
Raw Normal View History

import { vi } from "vitest";
import { GameManagerHelper } from "./gameManagerHelper";
2024-08-19 03:23:52 +01:00
import { MoveEffectPhase } from "#app/phases/move-effect-phase.js";
/**
* Helper to handle a Pokemon's move
*/
export class MoveHelper extends GameManagerHelper {
/**
* Intercepts `MoveEffectPhase` and mocks the hitCheck's
* return value to `true` {@linkcode MoveEffectPhase.hitCheck}.
* Used to force a move to hit.
*/
async forceHit(): Promise<void> {
await this.game.phaseInterceptor.to(MoveEffectPhase, false);
vi.spyOn(this.game.scene.getCurrentPhase() as MoveEffectPhase, "hitCheck").mockReturnValue(true);
}
/**
* Intercepts `MoveEffectPhase` and mocks the hitCheck's
* return value to `false` {@linkcode MoveEffectPhase.hitCheck}.
* Used to force a move to miss.
* @param firstTargetOnly Whether the move should force miss on the first target only, in the case of multi-target moves.
*/
async forceMiss(firstTargetOnly: boolean = false): Promise<void> {
await this.game.phaseInterceptor.to(MoveEffectPhase, false);
const hitCheck = vi.spyOn(this.game.scene.getCurrentPhase() as MoveEffectPhase, "hitCheck");
if (firstTargetOnly) {
hitCheck.mockReturnValueOnce(false);
} else {
hitCheck.mockReturnValue(false);
}
}
}