mirror of
https://github.com/pagefaultgames/pokerogue.git
synced 2025-08-16 12:29:26 +02:00
Fiexd up matchers
This commit is contained in:
parent
c28eacf256
commit
a0de157246
@ -36,7 +36,7 @@ export function toHaveAbilityAppliedMatcher(
|
|||||||
pass
|
pass
|
||||||
? `Expected ${pkmName} to NOT have applied ${expectedAbilityStr}, but it did!`
|
? `Expected ${pkmName} to NOT have applied ${expectedAbilityStr}, but it did!`
|
||||||
: `Expected ${pkmName} to have applied ${expectedAbilityStr}, but it did not!`,
|
: `Expected ${pkmName} to have applied ${expectedAbilityStr}, but it did not!`,
|
||||||
actual: received.waveData.abilitiesApplied,
|
|
||||||
expected: expectedAbilityId,
|
expected: expectedAbilityId,
|
||||||
|
actual: received.waveData.abilitiesApplied,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -4,7 +4,7 @@ import type { Pokemon } from "#field/pokemon";
|
|||||||
|
|
||||||
import { getPokemonNameWithAffix } from "#app/messages";
|
import { getPokemonNameWithAffix } from "#app/messages";
|
||||||
import { BattlerTagType } from "#enums/battler-tag-type";
|
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 { isPokemonInstance, receivedStr } from "#test/test-utils/test-utils";
|
||||||
import type { MatcherState, SyncExpectationResult } from "@vitest/expect";
|
import type { MatcherState, SyncExpectationResult } from "@vitest/expect";
|
||||||
|
|
||||||
@ -28,20 +28,16 @@ export function toHaveBattlerTag(
|
|||||||
|
|
||||||
const pass = !!received.getTag(expectedBattlerTagType);
|
const pass = !!received.getTag(expectedBattlerTagType);
|
||||||
const pkmName = getPokemonNameWithAffix(received);
|
const pkmName = getPokemonNameWithAffix(received);
|
||||||
// "the SEEDED BattlerTag (=1)"
|
// "BattlerTagType.SEEDED (=1)"
|
||||||
const expectedTagStr = getEnumStr(BattlerTagType, expectedBattlerTagType, { prefix: "the ", suffix: " BattlerTag" });
|
const expectedTagStr = getEnumStr(BattlerTagType, expectedBattlerTagType);
|
||||||
const actualTagStr = stringifyEnumArray(
|
|
||||||
BattlerTagType,
|
|
||||||
received.summonData.tags.map(t => t.tagType),
|
|
||||||
);
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
pass,
|
pass,
|
||||||
message: () =>
|
message: () =>
|
||||||
pass
|
pass
|
||||||
? `Expected ${pkmName} to NOT have ${expectedTagStr}, but it did!`
|
? `Expected ${pkmName} to NOT have BattlerTagType.${expectedTagStr}, but it did!`
|
||||||
: `Expected ${pkmName} to have ${expectedTagStr}, but it did not!`,
|
: `Expected ${pkmName} to have BattlerTagType.${expectedTagStr}, but it did not!`,
|
||||||
actual: actualTagStr,
|
expected: expectedBattlerTagType,
|
||||||
expected: getEnumStr(BattlerTagType, expectedBattlerTagType),
|
actual: received.summonData.tags.map(t => t.tagType),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -1,10 +1,10 @@
|
|||||||
import { getPokemonNameWithAffix } from "#app/messages";
|
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 { Pokemon } from "#field/pokemon";
|
||||||
import type { Move } from "#moves/move";
|
import type { Move } from "#moves/move";
|
||||||
|
import { getStatName } from "#test/test-utils/string-utils";
|
||||||
import { isPokemonInstance, receivedStr } from "#test/test-utils/test-utils";
|
import { isPokemonInstance, receivedStr } from "#test/test-utils/test-utils";
|
||||||
import type { MatcherState, SyncExpectationResult } from "@vitest/expect";
|
import type { MatcherState, SyncExpectationResult } from "@vitest/expect";
|
||||||
import i18next from "i18next";
|
|
||||||
|
|
||||||
export interface ToHaveEffectiveStatMatcherOptions {
|
export interface ToHaveEffectiveStatMatcherOptions {
|
||||||
/**
|
/**
|
||||||
@ -52,7 +52,7 @@ export function toHaveEffectiveStatMatcher(
|
|||||||
const pass = actualValue === expectedValue;
|
const pass = actualValue === expectedValue;
|
||||||
|
|
||||||
const pkmName = getPokemonNameWithAffix(received);
|
const pkmName = getPokemonNameWithAffix(received);
|
||||||
const statName = i18next.t(getStatKey(stat));
|
const statName = getStatName(stat);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
pass,
|
pass,
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
import { TerrainType } from "#app/data/terrain";
|
import { TerrainType } from "#app/data/terrain";
|
||||||
|
import { getEnumStr } from "#test/test-utils/string-utils";
|
||||||
import { isGameManagerInstance, receivedStr } from "#test/test-utils/test-utils";
|
import { isGameManagerInstance, receivedStr } from "#test/test-utils/test-utils";
|
||||||
import { toReadableString } from "#utils/common";
|
|
||||||
import type { MatcherState, SyncExpectationResult } from "@vitest/expect";
|
import type { MatcherState, SyncExpectationResult } from "@vitest/expect";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -39,8 +39,8 @@ export function toHaveTerrainMatcher(
|
|||||||
pass
|
pass
|
||||||
? `Expected Arena to NOT have ${expectedStr} active, but it did!`
|
? `Expected Arena to NOT have ${expectedStr} active, but it did!`
|
||||||
: `Expected Arena to have ${expectedStr} active, but got ${actualStr}!`,
|
: `Expected Arena to have ${expectedStr} active, but got ${actualStr}!`,
|
||||||
actual: actualStr,
|
actual,
|
||||||
expected: expectedStr,
|
expected: expectedTerrainType,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -53,6 +53,5 @@ function toTerrainStr(terrainType: TerrainType) {
|
|||||||
if (terrainType === TerrainType.NONE) {
|
if (terrainType === TerrainType.NONE) {
|
||||||
return "no terrain";
|
return "no terrain";
|
||||||
}
|
}
|
||||||
// TODO: Change to use updated string utils
|
return getEnumStr(TerrainType, terrainType, { casing: "Title", suffix: " Terrain" });
|
||||||
return toReadableString(TerrainType[terrainType] + " Terrain");
|
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
|
import { getStatKey, type Stat } from "#enums/stat";
|
||||||
import type { EnumOrObject, EnumValues, NormalEnum, TSNumericEnum } from "#types/enum-types";
|
import type { EnumOrObject, EnumValues, NormalEnum, TSNumericEnum } from "#types/enum-types";
|
||||||
import { toReadableString } from "#utils/common";
|
|
||||||
import { enumValueToKey } from "#utils/enums";
|
import { enumValueToKey } from "#utils/enums";
|
||||||
|
import { toTitleCase } from "#utils/strings";
|
||||||
|
import i18next from "i18next";
|
||||||
|
|
||||||
type Casing = "Preserve" | "Title";
|
type Casing = "Preserve" | "Title";
|
||||||
|
|
||||||
@ -11,7 +13,7 @@ interface getEnumStrOptions {
|
|||||||
*/
|
*/
|
||||||
casing?: Casing;
|
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;
|
prefix?: string;
|
||||||
/**
|
/**
|
||||||
@ -36,7 +38,7 @@ interface getEnumStrOptions {
|
|||||||
* THREE: 3,
|
* THREE: 3,
|
||||||
* }
|
* }
|
||||||
* console.log(getEnumStr(fakeEnum, fakeEnum.ONE)); // Output: "ONE (=1)"
|
* 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>(
|
export function getEnumStr<E extends EnumOrObject>(
|
||||||
@ -49,7 +51,7 @@ export function getEnumStr<E extends EnumOrObject>(
|
|||||||
case "Preserve":
|
case "Preserve":
|
||||||
break;
|
break;
|
||||||
case "Title":
|
case "Title":
|
||||||
casingFunc = toReadableString;
|
casingFunc = toTitleCase;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -126,3 +128,7 @@ export function getOrdinal(num: number): string {
|
|||||||
}
|
}
|
||||||
return num + "th";
|
return num + "th";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function getStatName(s: Stat): string {
|
||||||
|
return i18next.t(getStatKey(s));
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user