Added option to check for all PP used in pp matcher + cleaned up grudge tests

This commit is contained in:
Bertie690 2025-07-28 11:36:58 -04:00
parent 4b447073a7
commit 447bc59b40
2 changed files with 15 additions and 7 deletions

View File

@ -124,11 +124,12 @@ declare module "vitest" {
/** /**
* Check whether a {@linkcode Pokemon} has consumed the given amount of PP for one of its moves. * 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 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 * @remarks
* If the Pokemon's moveset has been set via {@linkcode Overrides.MOVESET_OVERRIDE}/{@linkcode Overrides.OPP_MOVESET_OVERRIDE} * 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. * 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;
} }
} }

View File

@ -12,7 +12,8 @@ import type { MatcherState, SyncExpectationResult } from "@vitest/expect";
* Matcher to check the amount of PP consumed by a {@linkcode Pokemon}. * Matcher to check the amount of PP consumed by a {@linkcode Pokemon}.
* @param received - The actual value received. Should be 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 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 * @returns Whether the matcher passed
* @remarks * @remarks
* If the same move appears in the Pokemon's moveset multiple times, this will fail the test! * 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, this: MatcherState,
received: unknown, received: unknown,
expectedMove: MoveId, expectedMove: MoveId,
ppUsed: number, ppUsed: number | "all",
): SyncExpectationResult { ): SyncExpectationResult {
if (!isPokemonInstance(received)) { if (!isPokemonInstance(received)) {
return { 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; const pass = move.ppUsed === ppUsed;
return { return {
pass, pass,
message: () => message: () =>
pass pass
? `Expected ${pkmName}'s ${moveStr} to NOT have used ${ppUsed} PP, but it did!` ? `Expected ${pkmName}'s ${moveStr} to NOT have used ${ppStr} PP, but it did!`
: `Expected ${pkmName}'s ${moveStr} to have used ${ppUsed} PP, but got ${move.ppUsed} instead!`, : `Expected ${pkmName}'s ${moveStr} to have used ${ppStr} PP, but got ${move.ppUsed} instead!`,
expected: ppUsed, expected: ppUsed,
actual: move.ppUsed, actual: move.ppUsed,
}; };