mirror of
https://github.com/pagefaultgames/pokerogue.git
synced 2025-08-15 03:49:33 +02:00
Added option to check for all PP used in pp matcher + cleaned up grudge tests
This commit is contained in:
parent
4b447073a7
commit
447bc59b40
5
test/@types/vitest.d.ts
vendored
5
test/@types/vitest.d.ts
vendored
@ -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;
|
||||
}
|
||||
}
|
||||
|
@ -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,
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user