From a0de157246e17f4b8599cc6b796c314e141bf1d2 Mon Sep 17 00:00:00 2001 From: Bertie690 Date: Sun, 27 Jul 2025 20:17:29 -0400 Subject: [PATCH] Fiexd up matchers --- .../matchers/to-have-ability-applied.ts | 2 +- .../test-utils/matchers/to-have-battler-tag.ts | 18 +++++++----------- .../matchers/to-have-effective-stat.ts | 6 +++--- .../matchers/to-have-terrain-matcher.ts | 9 ++++----- test/test-utils/string-utils.ts | 14 ++++++++++---- 5 files changed, 25 insertions(+), 24 deletions(-) diff --git a/test/test-utils/matchers/to-have-ability-applied.ts b/test/test-utils/matchers/to-have-ability-applied.ts index 6c78d23e2cb..1170850d844 100644 --- a/test/test-utils/matchers/to-have-ability-applied.ts +++ b/test/test-utils/matchers/to-have-ability-applied.ts @@ -36,7 +36,7 @@ export function toHaveAbilityAppliedMatcher( pass ? `Expected ${pkmName} to NOT have applied ${expectedAbilityStr}, but it did!` : `Expected ${pkmName} to have applied ${expectedAbilityStr}, but it did not!`, - actual: received.waveData.abilitiesApplied, expected: expectedAbilityId, + actual: received.waveData.abilitiesApplied, }; } diff --git a/test/test-utils/matchers/to-have-battler-tag.ts b/test/test-utils/matchers/to-have-battler-tag.ts index 304fe8f2626..51d020e8252 100644 --- a/test/test-utils/matchers/to-have-battler-tag.ts +++ b/test/test-utils/matchers/to-have-battler-tag.ts @@ -4,7 +4,7 @@ import type { Pokemon } from "#field/pokemon"; import { getPokemonNameWithAffix } from "#app/messages"; import { BattlerTagType } from "#enums/battler-tag-type"; -import { getEnumStr, stringifyEnumArray } from "#test/test-utils/string-utils"; +import { getEnumStr } from "#test/test-utils/string-utils"; import { isPokemonInstance, receivedStr } from "#test/test-utils/test-utils"; import type { MatcherState, SyncExpectationResult } from "@vitest/expect"; @@ -28,20 +28,16 @@ export function toHaveBattlerTag( const pass = !!received.getTag(expectedBattlerTagType); const pkmName = getPokemonNameWithAffix(received); - // "the SEEDED BattlerTag (=1)" - const expectedTagStr = getEnumStr(BattlerTagType, expectedBattlerTagType, { prefix: "the ", suffix: " BattlerTag" }); - const actualTagStr = stringifyEnumArray( - BattlerTagType, - received.summonData.tags.map(t => t.tagType), - ); + // "BattlerTagType.SEEDED (=1)" + const expectedTagStr = getEnumStr(BattlerTagType, expectedBattlerTagType); return { pass, message: () => pass - ? `Expected ${pkmName} to NOT have ${expectedTagStr}, but it did!` - : `Expected ${pkmName} to have ${expectedTagStr}, but it did not!`, - actual: actualTagStr, - expected: getEnumStr(BattlerTagType, expectedBattlerTagType), + ? `Expected ${pkmName} to NOT have BattlerTagType.${expectedTagStr}, but it did!` + : `Expected ${pkmName} to have BattlerTagType.${expectedTagStr}, but it did not!`, + expected: expectedBattlerTagType, + actual: received.summonData.tags.map(t => t.tagType), }; } diff --git a/test/test-utils/matchers/to-have-effective-stat.ts b/test/test-utils/matchers/to-have-effective-stat.ts index c5d755bd096..b0a1369269a 100644 --- a/test/test-utils/matchers/to-have-effective-stat.ts +++ b/test/test-utils/matchers/to-have-effective-stat.ts @@ -1,10 +1,10 @@ import { getPokemonNameWithAffix } from "#app/messages"; -import { type EffectiveStat, getStatKey } from "#enums/stat"; +import type { EffectiveStat } from "#enums/stat"; import type { Pokemon } from "#field/pokemon"; import type { Move } from "#moves/move"; +import { getStatName } from "#test/test-utils/string-utils"; import { isPokemonInstance, receivedStr } from "#test/test-utils/test-utils"; import type { MatcherState, SyncExpectationResult } from "@vitest/expect"; -import i18next from "i18next"; export interface ToHaveEffectiveStatMatcherOptions { /** @@ -52,7 +52,7 @@ export function toHaveEffectiveStatMatcher( const pass = actualValue === expectedValue; const pkmName = getPokemonNameWithAffix(received); - const statName = i18next.t(getStatKey(stat)); + const statName = getStatName(stat); return { pass, diff --git a/test/test-utils/matchers/to-have-terrain-matcher.ts b/test/test-utils/matchers/to-have-terrain-matcher.ts index 52fd1d176e9..67292ef8bd9 100644 --- a/test/test-utils/matchers/to-have-terrain-matcher.ts +++ b/test/test-utils/matchers/to-have-terrain-matcher.ts @@ -1,6 +1,6 @@ import { TerrainType } from "#app/data/terrain"; +import { getEnumStr } from "#test/test-utils/string-utils"; import { isGameManagerInstance, receivedStr } from "#test/test-utils/test-utils"; -import { toReadableString } from "#utils/common"; import type { MatcherState, SyncExpectationResult } from "@vitest/expect"; /** @@ -39,8 +39,8 @@ export function toHaveTerrainMatcher( pass ? `Expected Arena to NOT have ${expectedStr} active, but it did!` : `Expected Arena to have ${expectedStr} active, but got ${actualStr}!`, - actual: actualStr, - expected: expectedStr, + actual, + expected: expectedTerrainType, }; } @@ -53,6 +53,5 @@ function toTerrainStr(terrainType: TerrainType) { if (terrainType === TerrainType.NONE) { return "no terrain"; } - // TODO: Change to use updated string utils - return toReadableString(TerrainType[terrainType] + " Terrain"); + return getEnumStr(TerrainType, terrainType, { casing: "Title", suffix: " Terrain" }); } diff --git a/test/test-utils/string-utils.ts b/test/test-utils/string-utils.ts index 92342ceb036..6dcb7438f96 100644 --- a/test/test-utils/string-utils.ts +++ b/test/test-utils/string-utils.ts @@ -1,6 +1,8 @@ +import { getStatKey, type Stat } from "#enums/stat"; import type { EnumOrObject, EnumValues, NormalEnum, TSNumericEnum } from "#types/enum-types"; -import { toReadableString } from "#utils/common"; import { enumValueToKey } from "#utils/enums"; +import { toTitleCase } from "#utils/strings"; +import i18next from "i18next"; type Casing = "Preserve" | "Title"; @@ -11,7 +13,7 @@ interface getEnumStrOptions { */ casing?: Casing; /** - * If present, will be added to the beginning of the enum string. + * If present, will be prepended to the beginning of the enum string. */ prefix?: string; /** @@ -36,7 +38,7 @@ interface getEnumStrOptions { * THREE: 3, * } * console.log(getEnumStr(fakeEnum, fakeEnum.ONE)); // Output: "ONE (=1)" - * console.log(getEnumStr(fakeEnum, fakeEnum.TWO, {case: "Title", suffix: " Terrain"})); // Output: "Two Terrain (=2)" + * console.log(getEnumStr(fakeEnum, fakeEnum.TWO, {case: "Title", prefix: "fakeEnum."})); // Output: "fakeEnum.Two (=2)" * ``` */ export function getEnumStr( @@ -49,7 +51,7 @@ export function getEnumStr( case "Preserve": break; case "Title": - casingFunc = toReadableString; + casingFunc = toTitleCase; break; } @@ -126,3 +128,7 @@ export function getOrdinal(num: number): string { } return num + "th"; } + +export function getStatName(s: Stat): string { + return i18next.t(getStatKey(s)); +}