From c89accc6731549b490014343de0993b2f018c51a Mon Sep 17 00:00:00 2001 From: Bertie690 Date: Sun, 3 Aug 2025 16:26:39 -0400 Subject: [PATCH] Shuffled a few funcs around --- test/@types/vitest.d.ts | 89 ++++++++++--------- test/test-utils/matchers/to-have-arena-tag.ts | 5 +- 2 files changed, 51 insertions(+), 43 deletions(-) diff --git a/test/@types/vitest.d.ts b/test/@types/vitest.d.ts index 086675da78d..603acfb0bb5 100644 --- a/test/@types/vitest.d.ts +++ b/test/@types/vitest.d.ts @@ -1,5 +1,5 @@ import type { TerrainType } from "#app/data/terrain"; -import type { ArenaTag, ArenaTagTypeMap } from "#data/arena-tag"; +import type { ArenaTag } from "#data/arena-tag"; import type { AbilityId } from "#enums/ability-id"; import type { ArenaTagType } from "#enums/arena-tag-type"; import type { BattlerTagType } from "#enums/battler-tag-type"; @@ -21,7 +21,7 @@ import "vitest"; import type Overrides from "#app/overrides"; import type { ArenaTagSide } from "#enums/arena-tag-side"; import type { PokemonMove } from "#moves/pokemon-move"; -import type { OneOther } from "#test/@types/test-helpers"; +import { toHaveArenaTagOptions } from "#test/test-utils/matchers/to-have-arena-tag"; declare module "vitest" { interface Assertion { @@ -36,6 +36,38 @@ declare module "vitest" { */ toEqualArrayUnsorted(expected: T[]): void; + // #region Arena Matchers + + /** + * Check whether the current {@linkcode WeatherType} is as expected. + * @param expectedWeatherType - The expected {@linkcode WeatherType} + */ + toHaveWeather(expectedWeatherType: WeatherType): void; + + /** + * Check whether the current {@linkcode TerrainType} is as expected. + * @param expectedTerrainType - The expected {@linkcode TerrainType} + */ + toHaveTerrain(expectedTerrainType: TerrainType): void; + + /** + * Check whether the current {@linkcode Arena} contains the given {@linkcode ArenaTag}. + * @param expectedTag - A partially-filled {@linkcode ArenaTag} containing the desired properties + */ + toHaveArenaTag(expectedTag: toHaveArenaTagOptions): void; + /** + * Check whether the current {@linkcode Arena} contains the given {@linkcode ArenaTag}. + * @param expectedType - The {@linkcode ArenaTagType} of the desired tag + * @param side - The {@linkcode ArenaTagSide | side of the field} the tag should affect, or + * {@linkcode ArenaTagSide.BOTH} to check both sides; + * default `ArenaTagSide.BOTH` + */ + toHaveArenaTag(expectedType: ArenaTagType, side?: ArenaTagSide): void; + + // #endregion Arena Matchers + + // #region Pokemon Matchers + /** * Check whether a {@linkcode Pokemon}'s current typing includes the given types. * @param expectedTypes - The expected {@linkcode PokemonType}s to check against; must have length `>0` @@ -64,46 +96,6 @@ declare module "vitest" { */ toHaveEffectiveStat(stat: EffectiveStat, expectedValue: number, options?: toHaveEffectiveStatOptions): void; - /** - * Check whether a {@linkcode Pokemon} has taken a specific amount of damage. - * @param expectedDamageTaken - The expected amount of damage taken - * @param roundDown - Whether to round down {@linkcode expectedDamageTaken} with {@linkcode toDmgValue}; default `true` - */ - toHaveTakenDamage(expectedDamageTaken: number, roundDown?: boolean): void; - - /** - * Check whether the current {@linkcode WeatherType} is as expected. - * @param expectedWeatherType - The expected {@linkcode WeatherType} - */ - toHaveWeather(expectedWeatherType: WeatherType): void; - - /** - * Check whether the current {@linkcode TerrainType} is as expected. - * @param expectedTerrainType - The expected {@linkcode TerrainType} - */ - toHaveTerrain(expectedTerrainType: TerrainType): void; - - /** - * Check whether the current {@linkcode Arena} contains the given {@linkcode ArenaTag}. - * @param expectedTag - A partially-filled {@linkcode ArenaTag} containing the desired properties - */ - toHaveArenaTag( - expectedTag: OneOther & { tagType: T }, // intersection required to preserve T - ): void; - /** - * Check whether the current {@linkcode Arena} contains the given {@linkcode ArenaTag}. - * @param expectedType - The {@linkcode ArenaTagType} of the desired tag - * @param side - The {@linkcode ArenaTagSide | side of the field} the tag should affect, or - * {@linkcode ArenaTagSide.BOTH} to check both sides; - * default `ArenaTagSide.BOTH` - */ - toHaveArenaTag(expectedType: ArenaTagType, side?: ArenaTagSide): void; - - /** - * Check whether a {@linkcode Pokemon} is at full HP. - */ - toHaveFullHp(): void; - /** * Check whether a {@linkcode Pokemon} has a specific {@linkcode StatusEffect | non-volatile status effect}. * @param expectedStatusEffect - The {@linkcode StatusEffect} the Pokemon is expected to have, @@ -136,6 +128,13 @@ declare module "vitest" { */ toHaveHp(expectedHp: number): void; + /** + * Check whether a {@linkcode Pokemon} has taken a specific amount of damage. + * @param expectedDamageTaken - The expected amount of damage taken + * @param roundDown - Whether to round down {@linkcode expectedDamageTaken} with {@linkcode toDmgValue}; default `true` + */ + toHaveTakenDamage(expectedDamageTaken: number, roundDown?: boolean): void; + /** * Check whether a {@linkcode Pokemon} is currently fainted (as determined by {@linkcode Pokemon.isFainted}). * @remarks @@ -144,6 +143,10 @@ declare module "vitest" { */ toHaveFainted(): void; + /** + * Check whether a {@linkcode Pokemon} is at full HP. + */ + toHaveFullHp(): void; /** * Check whether a {@linkcode Pokemon} has consumed the given amount of PP for one of its moves. * @param moveId - The {@linkcode MoveId} of the {@linkcode PokemonMove} that should have consumed PP @@ -154,5 +157,7 @@ declare module "vitest" { * or does not contain exactly 1 copy of {@linkcode moveId}, this will fail the test. */ toHaveUsedPP(moveId: MoveId, ppUsed: number | "all"): void; + + // #region Pokemon Matchers } } diff --git a/test/test-utils/matchers/to-have-arena-tag.ts b/test/test-utils/matchers/to-have-arena-tag.ts index 1aba0009465..f02f350d3e3 100644 --- a/test/test-utils/matchers/to-have-arena-tag.ts +++ b/test/test-utils/matchers/to-have-arena-tag.ts @@ -9,7 +9,10 @@ import { isGameManagerInstance, receivedStr } from "#test/test-utils/test-utils" import type { NonFunctionPropertiesRecursive } from "#types/type-helpers"; import type { MatcherState, SyncExpectationResult } from "@vitest/expect"; -export type toHaveArenaTagOptions = OneOther; +// intersection required to preserve T for inferences +export type toHaveArenaTagOptions = OneOther & { + tagType: T; +}; /** * Matcher to check if the {@linkcode Arena} has a given {@linkcode ArenaTag} active.