pokerogue/test/test-utils/matchers/to-have-ability-applied.ts
Bertie690 ee4950633e
[Test] Added toHaveArenaTagMatcher + fixed prior matchers (#6205)
* [Test] Added `toHaveArenaTagMatcher` + fixed prior matchers

* Fixed imports and stuff

* Removed accidental test file addition

* More improvements and minor fixes

* More semantic changes

* Shuffled a few funcs around

* More fixups to strings

* Added `toHavePositionalTag` matcher

* Applied reviews and fixed my godawful penmanship

* Fix vitest.d.ts

* Fix imports in `vitest.d.ts`

---------

Co-authored-by: NightKev <34855794+DayKev@users.noreply.github.com>
Co-authored-by: Sirz Benjie <142067137+SirzBenjie@users.noreply.github.com>
2025-08-14 13:16:23 -07:00

44 lines
1.6 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 { AbilityId } from "#enums/ability-id";
import { getEnumStr } from "#test/test-utils/string-utils";
import { isPokemonInstance, receivedStr } from "#test/test-utils/test-utils";
import type { MatcherState, SyncExpectationResult } from "@vitest/expect";
/**
* Matcher that checks if a {@linkcode Pokemon} has applied a specific {@linkcode AbilityId}.
* @param received - The object to check. Should be a {@linkcode Pokemon}
* @param expectedAbility - The {@linkcode AbilityId} to check for
* @returns Whether the matcher passed
*/
export function toHaveAbilityApplied(
this: MatcherState,
received: unknown,
expectedAbilityId: AbilityId,
): SyncExpectationResult {
if (!isPokemonInstance(received)) {
return {
pass: this.isNot,
message: () => `Expected to receive a Pokemon, but got ${receivedStr(received)}!`,
};
}
const pass = received.waveData.abilitiesApplied.has(expectedAbilityId);
const pkmName = getPokemonNameWithAffix(received);
const expectedAbilityStr = getEnumStr(AbilityId, expectedAbilityId);
return {
pass,
message: () =>
pass
? `Expected ${pkmName} to NOT have applied ${expectedAbilityStr}, but it did!`
: `Expected ${pkmName} to have applied ${expectedAbilityStr}, but it didn't!`,
expected: expectedAbilityId,
actual: received.waveData.abilitiesApplied,
};
}