mirror of
https://github.com/pagefaultgames/pokerogue.git
synced 2025-08-10 17:39:31 +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
84 lines
3.3 KiB
TypeScript
84 lines
3.3 KiB
TypeScript
/* biome-ignore-start lint/correctness/noUnusedImports: tsdoc imports */
|
|
import type { Status } from "#data/status-effect";
|
|
import type { Pokemon } from "#field/pokemon";
|
|
/* biome-ignore-end lint/correctness/noUnusedImports: tsdoc imports */
|
|
|
|
import { getPokemonNameWithAffix } from "#app/messages";
|
|
import { StatusEffect } from "#enums/status-effect";
|
|
import { getEnumStr, getOnelineDiffStr } from "#test/test-utils/string-utils";
|
|
import { isPokemonInstance, receivedStr } from "#test/test-utils/test-utils";
|
|
import type { MatcherState, SyncExpectationResult } from "@vitest/expect";
|
|
|
|
export type expectedStatusType =
|
|
| StatusEffect
|
|
| { effect: StatusEffect.TOXIC; toxicTurnCount: number }
|
|
| { effect: StatusEffect.SLEEP; sleepTurnsRemaining: number };
|
|
|
|
/**
|
|
* Matcher that checks if a Pokemon's {@linkcode StatusEffect} is as expected
|
|
* @param received - The actual value received. Should be a {@linkcode Pokemon}
|
|
* @param expectedStatus - The {@linkcode StatusEffect} the Pokemon is expected to have,
|
|
* or a partially filled {@linkcode Status} containing the desired properties
|
|
* @returns Whether the matcher passed
|
|
*/
|
|
export function toHaveStatusEffect(
|
|
this: MatcherState,
|
|
received: unknown,
|
|
expectedStatus: expectedStatusType,
|
|
): SyncExpectationResult {
|
|
if (!isPokemonInstance(received)) {
|
|
return {
|
|
pass: false,
|
|
message: () => `Expected to receive a Pokémon, but got ${receivedStr(received)}!`,
|
|
};
|
|
}
|
|
|
|
const pkmName = getPokemonNameWithAffix(received);
|
|
const actualEffect = received.status?.effect ?? StatusEffect.NONE;
|
|
|
|
// Check exclusively effect equality first, coercing non-matching status effects to numbers.
|
|
if (actualEffect !== (expectedStatus as Exclude<typeof expectedStatus, StatusEffect>)?.effect) {
|
|
// This is actually 100% safe as `expectedStatus?.effect` will evaluate to `undefined` if a StatusEffect was passed,
|
|
// which will never match actualEffect by definition
|
|
expectedStatus = (expectedStatus as Exclude<typeof expectedStatus, StatusEffect>).effect;
|
|
}
|
|
|
|
if (typeof expectedStatus === "number") {
|
|
const pass = this.equals(actualEffect, expectedStatus, [...this.customTesters, this.utils.iterableEquality]);
|
|
|
|
const actualStr = getEnumStr(StatusEffect, actualEffect, { prefix: "StatusEffect." });
|
|
const expectedStr = getEnumStr(StatusEffect, expectedStatus, { prefix: "StatusEffect." });
|
|
|
|
return {
|
|
pass,
|
|
message: () =>
|
|
pass
|
|
? `Expected ${pkmName} to NOT have ${expectedStr}, but it did!`
|
|
: `Expected ${pkmName} to have status effect ${expectedStr}, but got ${actualStr} instead!`,
|
|
expected: expectedStatus,
|
|
actual: actualEffect,
|
|
};
|
|
}
|
|
|
|
// Check for equality of all fields (for toxic turn count/etc)
|
|
const actualStatus = received.status;
|
|
const pass = this.equals(received, expectedStatus, [
|
|
...this.customTesters,
|
|
this.utils.subsetEquality,
|
|
this.utils.iterableEquality,
|
|
]);
|
|
|
|
const expectedStr = getOnelineDiffStr.call(this, expectedStatus);
|
|
const actualStr = getOnelineDiffStr.call(this, actualStatus);
|
|
|
|
return {
|
|
pass,
|
|
message: () =>
|
|
pass
|
|
? `Expected ${pkmName}'s status to NOT match ${expectedStr}, but it did!`
|
|
: `Expected ${pkmName}'s status to match ${expectedStr}, but got ${actualStr} instead!`,
|
|
expected: expectedStatus,
|
|
actual: actualStatus,
|
|
};
|
|
}
|