Fiexd up matchers

This commit is contained in:
Bertie690 2025-07-27 20:17:29 -04:00
parent c28eacf256
commit a0de157246
5 changed files with 25 additions and 24 deletions

View File

@ -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,
};
}

View File

@ -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),
};
}

View File

@ -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,

View File

@ -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" });
}

View File

@ -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<E extends EnumOrObject>(
@ -49,7 +51,7 @@ export function getEnumStr<E extends EnumOrObject>(
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));
}