mirror of
https://github.com/pagefaultgames/pokerogue.git
synced 2025-08-11 09:59:28 +02:00
* Partially ported over pkty matchers (WIP) * Cleaned up some more matchers * Fiexd up matchers * Fixed up remaining matchers * Removed the word "matcher" from the pkty matcher functions If we want them back we can always undo this commit and convert the other custom ones * Added wip spite test * Added `toHaveUsedPP` matcher * Fixed up docs and tests * Fixed spite test * Ran biome * Apply Biome * Reverted biome breaking i18next * Update src/typings/i18next.d.ts comment * Fixed log message to not be overly verbose * Added option to check for all PP used in pp matcher + cleaned up grudge tests * Fixed up tests * Fixed tests and such * Fix various TSDocs + missing TSDoc imports
47 lines
1.8 KiB
TypeScript
47 lines
1.8 KiB
TypeScript
/** biome-ignore-start lint/correctness/noUnusedImports: TSDoc imports */
|
|
import type { Pokemon } from "#field/pokemon";
|
|
/** biome-ignore-end lint/correctness/noUnusedImports: TSDoc imports */
|
|
|
|
import { getPokemonNameWithAffix } from "#app/messages";
|
|
import { isPokemonInstance, receivedStr } from "#test/test-utils/test-utils";
|
|
import { toDmgValue } from "#utils/common";
|
|
import type { MatcherState, SyncExpectationResult } from "@vitest/expect";
|
|
|
|
/**
|
|
* Matcher that checks if a Pokemon has taken a specific amount of damage.
|
|
* Unless specified, will run the expected damage value through {@linkcode toDmgValue}
|
|
* to round it down and make it a minimum of 1.
|
|
* @param received - The object to check. Should be a {@linkcode Pokemon}.
|
|
* @param expectedDamageTaken - The expected amount of damage the {@linkcode Pokemon} has taken
|
|
* @param roundDown - Whether to round down {@linkcode expectedDamageTaken} with {@linkcode toDmgValue}; default `true`
|
|
* @returns Whether the matcher passed
|
|
*/
|
|
export function toHaveTakenDamage(
|
|
this: MatcherState,
|
|
received: unknown,
|
|
expectedDamageTaken: number,
|
|
roundDown = true,
|
|
): SyncExpectationResult {
|
|
if (!isPokemonInstance(received)) {
|
|
return {
|
|
pass: false,
|
|
message: () => `Expected to receive a Pokémon, but got ${receivedStr(received)}!`,
|
|
};
|
|
}
|
|
|
|
const expectedDmgValue = roundDown ? toDmgValue(expectedDamageTaken) : expectedDamageTaken;
|
|
const actualDmgValue = received.getInverseHp();
|
|
const pass = actualDmgValue === expectedDmgValue;
|
|
const pkmName = getPokemonNameWithAffix(received);
|
|
|
|
return {
|
|
pass,
|
|
message: () =>
|
|
pass
|
|
? `Expected ${pkmName} to NOT have taken ${expectedDmgValue} damage, but it did!`
|
|
: `Expected ${pkmName} to have taken ${expectedDmgValue} damage, but got ${actualDmgValue} instead!`,
|
|
expected: expectedDmgValue,
|
|
actual: actualDmgValue,
|
|
};
|
|
}
|