From 447bc59b4034692771fd7777ac577073d0282741 Mon Sep 17 00:00:00 2001 From: Bertie690 Date: Mon, 28 Jul 2025 11:36:58 -0400 Subject: [PATCH] Added option to check for all PP used in pp matcher + cleaned up grudge tests --- test/@types/vitest.d.ts | 5 +++-- test/test-utils/matchers/to-have-used-pp.ts | 17 ++++++++++++----- 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/test/@types/vitest.d.ts b/test/@types/vitest.d.ts index 905d65173f8..21b8e6b09aa 100644 --- a/test/@types/vitest.d.ts +++ b/test/@types/vitest.d.ts @@ -124,11 +124,12 @@ declare module "vitest" { /** * Check whether a {@linkcode Pokemon} has consumed the given amount of PP for one of its moves. * @param expectedValue - The {@linkcode MoveId} of the {@linkcode PokemonMove} that should have consumed PP - * @param ppUsed - The amount of PP that should have been consumed + * @param ppUsed - The numerical amount of PP that should have been consumed, + * or `all` to indicate the move should be _out_ of PP * @remarks * If the Pokemon's moveset has been set via {@linkcode Overrides.MOVESET_OVERRIDE}/{@linkcode Overrides.OPP_MOVESET_OVERRIDE} * or contains the desired move more than once, this will fail the test. */ - toHaveUsedPP(expectedMove: MoveId, ppUsed?: number): void; + toHaveUsedPP(expectedMove: MoveId, ppUsed: number | "all"): void; } } diff --git a/test/test-utils/matchers/to-have-used-pp.ts b/test/test-utils/matchers/to-have-used-pp.ts index 5a4036cbe3a..661208e2609 100644 --- a/test/test-utils/matchers/to-have-used-pp.ts +++ b/test/test-utils/matchers/to-have-used-pp.ts @@ -12,7 +12,8 @@ import type { MatcherState, SyncExpectationResult } from "@vitest/expect"; * Matcher to check the amount of PP consumed by a {@linkcode Pokemon}. * @param received - The actual value received. Should be a {@linkcode Pokemon} * @param expectedValue - The {@linkcode MoveId} that should have consumed PP - * @param ppUsed - The amount of PP that should have been consumed + * @param ppUsed - The numerical amount of PP that should have been consumed, + * or `all` to indicate the move should be _out_ of PP * @returns Whether the matcher passed * @remarks * If the same move appears in the Pokemon's moveset multiple times, this will fail the test! @@ -21,7 +22,7 @@ export function toHaveUsedPP( this: MatcherState, received: unknown, expectedMove: MoveId, - ppUsed: number, + ppUsed: number | "all", ): SyncExpectationResult { if (!isPokemonInstance(received)) { return { @@ -52,15 +53,21 @@ export function toHaveUsedPP( }; } - const move = movesetMoves[0]; + const move = movesetMoves[0]; // will be the only move in the array + + let ppStr: string = ppUsed.toString(); + if (typeof ppUsed === "string") { + ppStr = "all its"; + ppUsed = move.getMovePp(); + } const pass = move.ppUsed === ppUsed; return { pass, message: () => pass - ? `Expected ${pkmName}'s ${moveStr} to NOT have used ${ppUsed} PP, but it did!` - : `Expected ${pkmName}'s ${moveStr} to have used ${ppUsed} PP, but got ${move.ppUsed} instead!`, + ? `Expected ${pkmName}'s ${moveStr} to NOT have used ${ppStr} PP, but it did!` + : `Expected ${pkmName}'s ${moveStr} to have used ${ppStr} PP, but got ${move.ppUsed} instead!`, expected: ppUsed, actual: move.ppUsed, };