mirror of
https://github.com/pagefaultgames/pokerogue.git
synced 2025-08-25 16:59:27 +02:00
Compare commits
20 Commits
f476401257
...
85d55bf9c6
Author | SHA1 | Date | |
---|---|---|---|
|
85d55bf9c6 | ||
|
0da37a0f0c | ||
|
1d1ad8e9dc | ||
|
24f3d75055 | ||
|
839a099b3a | ||
|
c07f786042 | ||
|
6866248b41 | ||
|
9298ff8282 | ||
|
7e7ca6b3fa | ||
|
cd890025d1 | ||
|
71801fe298 | ||
|
e968063eaa | ||
|
b98ff5ae90 | ||
|
c89accc673 | ||
|
df8d1dc8c7 | ||
|
9455030fbe | ||
|
dbea701d6d | ||
|
641f5f5b97 | ||
|
f5154179b3 | ||
|
49825a6729 |
@ -1,13 +1,24 @@
|
||||
import type { Pokemon } from "#field/pokemon";
|
||||
import type {
|
||||
AttackMove,
|
||||
ChargingAttackMove,
|
||||
ChargingSelfStatusMove,
|
||||
Move,
|
||||
MoveAttr,
|
||||
MoveAttrConstructorMap,
|
||||
SelfStatusMove,
|
||||
StatusMove,
|
||||
} from "#moves/move";
|
||||
|
||||
/**
|
||||
* A generic function producing a message during a Move's execution.
|
||||
* @param user - The {@linkcode Pokemon} using the move
|
||||
* @param target - The {@linkcode Pokemon} targeted by the move
|
||||
* @param move - The {@linkcode Move} being used
|
||||
* @returns a string
|
||||
*/
|
||||
export type MoveMessageFunc = (user: Pokemon, target: Pokemon, move: Move) => string;
|
||||
|
||||
export type MoveAttrFilter = (attr: MoveAttr) => boolean;
|
||||
|
||||
export type * from "#moves/move";
|
||||
|
@ -1670,6 +1670,7 @@ export class MoveTypeChangeAbAttr extends PreAttackAbAttr {
|
||||
constructor(
|
||||
private newType: PokemonType,
|
||||
private powerMultiplier: number,
|
||||
// TODO: all moves with this attr solely check the move being used...
|
||||
private condition?: PokemonAttackCondition,
|
||||
) {
|
||||
super(false);
|
||||
|
@ -86,7 +86,7 @@ import { PokemonHealPhase } from "#phases/pokemon-heal-phase";
|
||||
import { SwitchSummonPhase } from "#phases/switch-summon-phase";
|
||||
import type { AttackMoveResult } from "#types/attack-move-result";
|
||||
import type { Localizable } from "#types/locales";
|
||||
import type { ChargingMove, MoveAttrMap, MoveAttrString, MoveClassMap, MoveKindString } from "#types/move-types";
|
||||
import type { ChargingMove, MoveAttrMap, MoveAttrString, MoveClassMap, MoveKindString, MoveMessageFunc } from "#types/move-types";
|
||||
import type { TurnMove } from "#types/turn-move";
|
||||
import { BooleanHolder, type Constructor, isNullOrUndefined, NumberHolder, randSeedFloat, randSeedInt, randSeedItem, toDmgValue } from "#utils/common";
|
||||
import { getEnumValues } from "#utils/enums";
|
||||
@ -1357,20 +1357,20 @@ export class MoveHeaderAttr extends MoveAttr {
|
||||
|
||||
/**
|
||||
* Header attribute to queue a message at the beginning of a turn.
|
||||
* @see {@link MoveHeaderAttr}
|
||||
*/
|
||||
export class MessageHeaderAttr extends MoveHeaderAttr {
|
||||
private message: string | ((user: Pokemon, move: Move) => string);
|
||||
/** The message to display, or a function producing one. */
|
||||
private message: string | MoveMessageFunc;
|
||||
|
||||
constructor(message: string | ((user: Pokemon, move: Move) => string)) {
|
||||
constructor(message: string | MoveMessageFunc) {
|
||||
super();
|
||||
this.message = message;
|
||||
}
|
||||
|
||||
apply(user: Pokemon, target: Pokemon, move: Move, args: any[]): boolean {
|
||||
apply(user: Pokemon, target: Pokemon, move: Move): boolean {
|
||||
const message = typeof this.message === "string"
|
||||
? this.message
|
||||
: this.message(user, move);
|
||||
: this.message(user, target, move);
|
||||
|
||||
if (message) {
|
||||
globalScene.phaseManager.queueMessage(message);
|
||||
@ -1418,21 +1418,21 @@ export class BeakBlastHeaderAttr extends AddBattlerTagHeaderAttr {
|
||||
*/
|
||||
export class PreMoveMessageAttr extends MoveAttr {
|
||||
/** The message to display or a function returning one */
|
||||
private message: string | ((user: Pokemon, target: Pokemon, move: Move) => string | undefined);
|
||||
private message: string | MoveMessageFunc;
|
||||
|
||||
/**
|
||||
* Create a new {@linkcode PreMoveMessageAttr} to display a message before move execution.
|
||||
* @param message - The message to display before move use, either as a string or a function producing one.
|
||||
* @param message - The message to display before move use, either` a literal string or a function producing one.
|
||||
* @remarks
|
||||
* If {@linkcode message} evaluates to an empty string (`''`), no message will be displayed
|
||||
* If {@linkcode message} evaluates to an empty string (`""`), no message will be displayed
|
||||
* (though the move will still succeed).
|
||||
*/
|
||||
constructor(message: string | ((user: Pokemon, target: Pokemon, move: Move) => string)) {
|
||||
constructor(message: string | MoveMessageFunc) {
|
||||
super();
|
||||
this.message = message;
|
||||
}
|
||||
|
||||
apply(user: Pokemon, target: Pokemon, move: Move, _args: any[]): boolean {
|
||||
apply(user: Pokemon, target: Pokemon, move: Move): boolean {
|
||||
const message = typeof this.message === "function"
|
||||
? this.message(user, target, move)
|
||||
: this.message;
|
||||
@ -1453,18 +1453,17 @@ export class PreMoveMessageAttr extends MoveAttr {
|
||||
* @extends MoveAttr
|
||||
*/
|
||||
export class PreUseInterruptAttr extends MoveAttr {
|
||||
protected message?: string | ((user: Pokemon, target: Pokemon, move: Move) => string);
|
||||
protected overridesFailedMessage: boolean;
|
||||
protected message: string | MoveMessageFunc;
|
||||
protected conditionFunc: MoveConditionFunc;
|
||||
|
||||
/**
|
||||
* Create a new MoveInterruptedMessageAttr.
|
||||
* @param message The message to display when the move is interrupted, or a function that formats the message based on the user, target, and move.
|
||||
*/
|
||||
constructor(message?: string | ((user: Pokemon, target: Pokemon, move: Move) => string), conditionFunc?: MoveConditionFunc) {
|
||||
constructor(message: string | MoveMessageFunc, conditionFunc: MoveConditionFunc) {
|
||||
super();
|
||||
this.message = message;
|
||||
this.conditionFunc = conditionFunc ?? (() => true);
|
||||
this.conditionFunc = conditionFunc;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -1485,11 +1484,9 @@ export class PreUseInterruptAttr extends MoveAttr {
|
||||
*/
|
||||
override getFailedText(user: Pokemon, target: Pokemon, move: Move): string | undefined {
|
||||
if (this.message && this.conditionFunc(user, target, move)) {
|
||||
const message =
|
||||
typeof this.message === "string"
|
||||
? (this.message as string)
|
||||
return typeof this.message === "string"
|
||||
? this.message
|
||||
: this.message(user, target, move);
|
||||
return message;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1694,17 +1691,30 @@ export class SurviveDamageAttr extends ModifiedDamageAttr {
|
||||
}
|
||||
}
|
||||
|
||||
export class SplashAttr extends MoveEffectAttr {
|
||||
apply(user: Pokemon, target: Pokemon, move: Move, args: any[]): boolean {
|
||||
globalScene.phaseManager.queueMessage(i18next.t("moveTriggers:splash"));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Move attribute to display arbitrary text during a move's execution.
|
||||
*/
|
||||
export class MessageAttr extends MoveEffectAttr {
|
||||
/** The message to display, either as a string or a function returning one. */
|
||||
private message: string | MoveMessageFunc;
|
||||
|
||||
export class CelebrateAttr extends MoveEffectAttr {
|
||||
apply(user: Pokemon, target: Pokemon, move: Move, args: any[]): boolean {
|
||||
globalScene.phaseManager.queueMessage(i18next.t("moveTriggers:celebrate", { playerName: loggedInUser?.username }));
|
||||
return true;
|
||||
constructor(message: string | MoveMessageFunc, options?: MoveEffectAttrOptions) {
|
||||
// TODO: Do we need to respect `selfTarget` if we're just displaying text?
|
||||
super(false, options)
|
||||
this.message = message;
|
||||
}
|
||||
|
||||
override apply(user: Pokemon, target: Pokemon, move: Move): boolean {
|
||||
const message = typeof this.message === "function"
|
||||
? this.message(user, target, move)
|
||||
: this.message;
|
||||
|
||||
// TODO: Consider changing if/when MoveAttr `apply` return values become significant
|
||||
if (message) {
|
||||
globalScene.phaseManager.queueMessage(message, 500);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@ -5931,38 +5941,6 @@ export class ProtectAttr extends AddBattlerTagAttr {
|
||||
}
|
||||
}
|
||||
|
||||
export class IgnoreAccuracyAttr extends AddBattlerTagAttr {
|
||||
constructor() {
|
||||
super(BattlerTagType.IGNORE_ACCURACY, true, false, 2);
|
||||
}
|
||||
|
||||
apply(user: Pokemon, target: Pokemon, move: Move, args: any[]): boolean {
|
||||
if (!super.apply(user, target, move, args)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
globalScene.phaseManager.queueMessage(i18next.t("moveTriggers:tookAimAtTarget", { pokemonName: getPokemonNameWithAffix(user), targetName: getPokemonNameWithAffix(target) }));
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
export class FaintCountdownAttr extends AddBattlerTagAttr {
|
||||
constructor() {
|
||||
super(BattlerTagType.PERISH_SONG, false, true, 4);
|
||||
}
|
||||
|
||||
apply(user: Pokemon, target: Pokemon, move: Move, args: any[]): boolean {
|
||||
if (!super.apply(user, target, move, args)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
globalScene.phaseManager.queueMessage(i18next.t("moveTriggers:faintCountdown", { pokemonName: getPokemonNameWithAffix(target), turnCount: this.turnCountMin - 1 }));
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Attribute to remove all Substitutes from the field.
|
||||
* @extends MoveEffectAttr
|
||||
@ -6603,8 +6581,10 @@ export class ChillyReceptionAttr extends ForceSwitchOutAttr {
|
||||
return (user, target, move) => globalScene.arena.weather?.weatherType !== WeatherType.SNOW || super.getSwitchOutCondition()(user, target, move);
|
||||
}
|
||||
}
|
||||
|
||||
export class RemoveTypeAttr extends MoveEffectAttr {
|
||||
|
||||
// TODO: Remove the message callback
|
||||
private removedType: PokemonType;
|
||||
private messageCallback: ((user: Pokemon) => void) | undefined;
|
||||
|
||||
@ -8299,8 +8279,6 @@ const MoveAttrs = Object.freeze({
|
||||
RandomLevelDamageAttr,
|
||||
ModifiedDamageAttr,
|
||||
SurviveDamageAttr,
|
||||
SplashAttr,
|
||||
CelebrateAttr,
|
||||
RecoilAttr,
|
||||
SacrificialAttr,
|
||||
SacrificialAttrOnHit,
|
||||
@ -8443,8 +8421,7 @@ const MoveAttrs = Object.freeze({
|
||||
RechargeAttr,
|
||||
TrapAttr,
|
||||
ProtectAttr,
|
||||
IgnoreAccuracyAttr,
|
||||
FaintCountdownAttr,
|
||||
MessageAttr,
|
||||
RemoveAllSubstitutesAttr,
|
||||
HitsTagAttr,
|
||||
HitsTagForDoubleDamageAttr,
|
||||
@ -8938,7 +8915,7 @@ export function initMoves() {
|
||||
new AttackMove(MoveId.PSYWAVE, PokemonType.PSYCHIC, MoveCategory.SPECIAL, -1, 100, 15, -1, 0, 1)
|
||||
.attr(RandomLevelDamageAttr),
|
||||
new SelfStatusMove(MoveId.SPLASH, PokemonType.NORMAL, -1, 40, -1, 0, 1)
|
||||
.attr(SplashAttr)
|
||||
.attr(MessageAttr, i18next.t("moveTriggers:splash"))
|
||||
.condition(failOnGravityCondition),
|
||||
new SelfStatusMove(MoveId.ACID_ARMOR, PokemonType.POISON, -1, 20, -1, 0, 1)
|
||||
.attr(StatStageChangeAttr, [ Stat.DEF ], 2, true),
|
||||
@ -9000,7 +8977,10 @@ export function initMoves() {
|
||||
.attr(AddBattlerTagAttr, BattlerTagType.TRAPPED, false, true, 1)
|
||||
.reflectable(),
|
||||
new StatusMove(MoveId.MIND_READER, PokemonType.NORMAL, -1, 5, -1, 0, 2)
|
||||
.attr(IgnoreAccuracyAttr),
|
||||
.attr(AddBattlerTagAttr, BattlerTagType.IGNORE_ACCURACY, true, false, 2)
|
||||
.attr(MessageAttr, (user, target) =>
|
||||
i18next.t("moveTriggers:tookAimAtTarget", { pokemonName: getPokemonNameWithAffix(user), targetName: getPokemonNameWithAffix(target) })
|
||||
),
|
||||
new StatusMove(MoveId.NIGHTMARE, PokemonType.GHOST, 100, 15, -1, 0, 2)
|
||||
.attr(AddBattlerTagAttr, BattlerTagType.NIGHTMARE)
|
||||
.condition(targetSleptOrComatoseCondition),
|
||||
@ -9088,7 +9068,9 @@ export function initMoves() {
|
||||
return lastTurnMove.length === 0 || lastTurnMove[0].move !== move.id || lastTurnMove[0].result !== MoveResult.SUCCESS;
|
||||
}),
|
||||
new StatusMove(MoveId.PERISH_SONG, PokemonType.NORMAL, -1, 5, -1, 0, 2)
|
||||
.attr(FaintCountdownAttr)
|
||||
.attr(AddBattlerTagAttr, BattlerTagType.PERISH_SONG, false, true, 4)
|
||||
.attr(MessageAttr, (_user, target) =>
|
||||
i18next.t("moveTriggers:faintCountdown", { pokemonName: getPokemonNameWithAffix(target), turnCount: 3 }))
|
||||
.ignoresProtect()
|
||||
.soundBased()
|
||||
.condition(failOnBossCondition)
|
||||
@ -9104,7 +9086,10 @@ export function initMoves() {
|
||||
.attr(MultiHitAttr)
|
||||
.makesContact(false),
|
||||
new StatusMove(MoveId.LOCK_ON, PokemonType.NORMAL, -1, 5, -1, 0, 2)
|
||||
.attr(IgnoreAccuracyAttr),
|
||||
.attr(AddBattlerTagAttr, BattlerTagType.IGNORE_ACCURACY, true, false, 2)
|
||||
.attr(MessageAttr, (user, target) =>
|
||||
i18next.t("moveTriggers:tookAimAtTarget", { pokemonName: getPokemonNameWithAffix(user), targetName: getPokemonNameWithAffix(target) })
|
||||
),
|
||||
new AttackMove(MoveId.OUTRAGE, PokemonType.DRAGON, MoveCategory.PHYSICAL, 120, 100, 10, -1, 0, 2)
|
||||
.attr(FrenzyAttr)
|
||||
.attr(MissEffectAttr, frenzyMissFunc)
|
||||
@ -9331,8 +9316,8 @@ export function initMoves() {
|
||||
&& (user.status.effect === StatusEffect.BURN || user.status.effect === StatusEffect.POISON || user.status.effect === StatusEffect.TOXIC || user.status.effect === StatusEffect.PARALYSIS) ? 2 : 1)
|
||||
.attr(BypassBurnDamageReductionAttr),
|
||||
new AttackMove(MoveId.FOCUS_PUNCH, PokemonType.FIGHTING, MoveCategory.PHYSICAL, 150, 100, 20, -1, -3, 3)
|
||||
.attr(MessageHeaderAttr, (user, move) => i18next.t("moveTriggers:isTighteningFocus", { pokemonName: getPokemonNameWithAffix(user) }))
|
||||
.attr(PreUseInterruptAttr, (user, target, move) => i18next.t("moveTriggers:lostFocus", { pokemonName: getPokemonNameWithAffix(user) }), user => !!user.turnData.attacksReceived.find(r => r.damage))
|
||||
.attr(MessageHeaderAttr, (user) => i18next.t("moveTriggers:isTighteningFocus", { pokemonName: getPokemonNameWithAffix(user) }))
|
||||
.attr(PreUseInterruptAttr, (user) => i18next.t("moveTriggers:lostFocus", { pokemonName: getPokemonNameWithAffix(user) }), user => user.turnData.attacksReceived.some(r => r.damage > 0))
|
||||
.punchingMove(),
|
||||
new AttackMove(MoveId.SMELLING_SALTS, PokemonType.NORMAL, MoveCategory.PHYSICAL, 70, 100, 10, -1, 0, 3)
|
||||
.attr(MovePowerMultiplierAttr, (user, target, move) => target.status?.effect === StatusEffect.PARALYSIS ? 2 : 1)
|
||||
@ -10433,7 +10418,8 @@ export function initMoves() {
|
||||
new AttackMove(MoveId.DAZZLING_GLEAM, PokemonType.FAIRY, MoveCategory.SPECIAL, 80, 100, 10, -1, 0, 6)
|
||||
.target(MoveTarget.ALL_NEAR_ENEMIES),
|
||||
new SelfStatusMove(MoveId.CELEBRATE, PokemonType.NORMAL, -1, 40, -1, 0, 6)
|
||||
.attr(CelebrateAttr),
|
||||
// NB: This needs a lambda function as the user will not be logged in by the time the moves are initialized
|
||||
.attr(MessageAttr, () => i18next.t("moveTriggers:celebrate", { playerName: loggedInUser?.username })),
|
||||
new StatusMove(MoveId.HOLD_HANDS, PokemonType.NORMAL, -1, 40, -1, 0, 6)
|
||||
.ignoresSubstitute()
|
||||
.target(MoveTarget.NEAR_ALLY),
|
||||
@ -10608,7 +10594,12 @@ export function initMoves() {
|
||||
.attr(StatStageChangeAttr, [ Stat.SPD ], -1)
|
||||
.reflectable(),
|
||||
new SelfStatusMove(MoveId.LASER_FOCUS, PokemonType.NORMAL, -1, 30, -1, 0, 7)
|
||||
.attr(AddBattlerTagAttr, BattlerTagType.ALWAYS_CRIT, true, false),
|
||||
.attr(AddBattlerTagAttr, BattlerTagType.ALWAYS_CRIT, true, false)
|
||||
.attr(MessageAttr, (user) =>
|
||||
i18next.t("battlerTags:laserFocusOnAdd", {
|
||||
pokemonNameWithAffix: getPokemonNameWithAffix(user),
|
||||
}),
|
||||
),
|
||||
new StatusMove(MoveId.GEAR_UP, PokemonType.STEEL, -1, 20, -1, 0, 7)
|
||||
.attr(StatStageChangeAttr, [ Stat.ATK, Stat.SPATK ], 1, false, { condition: (user, target, move) => !![ AbilityId.PLUS, AbilityId.MINUS ].find(a => target.hasAbility(a, false)) })
|
||||
.ignoresSubstitute()
|
||||
|
@ -11,7 +11,7 @@ import { BooleanHolder, toDmgValue } from "#utils/common";
|
||||
* These are the moves assigned to a {@linkcode Pokemon} object.
|
||||
* It links to {@linkcode Move} class via the move ID.
|
||||
* Compared to {@linkcode Move}, this class also tracks things like
|
||||
* PP Ups recieved, PP used, etc.
|
||||
* PP Ups received, PP used, etc.
|
||||
* @see {@linkcode isUsable} - checks if move is restricted, out of PP, or not implemented.
|
||||
* @see {@linkcode getMove} - returns {@linkcode Move} object by looking it up via ID.
|
||||
* @see {@linkcode usePp} - removes a point of PP from the move.
|
||||
|
27
test/@types/test-helpers.ts
Normal file
27
test/@types/test-helpers.ts
Normal file
@ -0,0 +1,27 @@
|
||||
import type { AtLeastOne, NonFunctionPropertiesRecursive as nonFunc } from "#types/type-helpers";
|
||||
|
||||
/**
|
||||
* Helper type to admit an object containing the given properties
|
||||
* _and_ at least 1 other non-function property.
|
||||
* @example
|
||||
* ```ts
|
||||
* type foo = {
|
||||
* qux: 1 | 2 | 3,
|
||||
* bar: number,
|
||||
* baz: string
|
||||
* quux: () => void; // ignored!
|
||||
* }
|
||||
*
|
||||
* type quxAndSomethingElse = OneOther<foo, "qux">
|
||||
*
|
||||
* const good1: quxAndSomethingElse = {qux: 1, bar: 3} // OK!
|
||||
* const good2: quxAndSomethingElse = {qux: 2, baz: "4", bar: 12} // OK!
|
||||
* const bad1: quxAndSomethingElse = {baz: "4", bar: 12} // Errors because `qux` is required
|
||||
* const bad2: quxAndSomethingElse = {qux: 1} // Errors because at least 1 thing _other_ than `qux` is required
|
||||
* ```
|
||||
* @typeParam O - The object to source keys from
|
||||
* @typeParam K - One or more of O's keys to render mandatory
|
||||
*/
|
||||
export type OneOther<O extends object, K extends keyof O> = AtLeastOne<Omit<nonFunc<O>, K>> & {
|
||||
[key in K]: O[K];
|
||||
};
|
136
test/@types/vitest.d.ts
vendored
136
test/@types/vitest.d.ts
vendored
@ -1,23 +1,32 @@
|
||||
import type { TerrainType } from "#app/data/terrain";
|
||||
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";
|
||||
import type { MoveId } from "#enums/move-id";
|
||||
import type { PokemonType } from "#enums/pokemon-type";
|
||||
import type { BattleStat, EffectiveStat, Stat } from "#enums/stat";
|
||||
import type { StatusEffect } from "#enums/status-effect";
|
||||
import type { WeatherType } from "#enums/weather-type";
|
||||
import type { Arena } from "#field/arena";
|
||||
import type { Pokemon } from "#field/pokemon";
|
||||
import type { ToHaveEffectiveStatMatcherOptions } from "#test/test-utils/matchers/to-have-effective-stat";
|
||||
import type { toHaveEffectiveStatOptions } from "#test/test-utils/matchers/to-have-effective-stat";
|
||||
import type { expectedStatusType } from "#test/test-utils/matchers/to-have-status-effect";
|
||||
import type { toHaveTypesOptions } from "#test/test-utils/matchers/to-have-types";
|
||||
import type { TurnMove } from "#types/turn-move";
|
||||
import type { AtLeastOne } from "#types/type-helpers";
|
||||
import type { toDmgValue } from "utils/common";
|
||||
import type { expect } from "vitest";
|
||||
import type { PositionalTag } from "#data/positional-tags/positional-tag";
|
||||
import { PositionalTagType } from "#enums/positional-tag-type";
|
||||
import type Overrides from "#app/overrides";
|
||||
import type { ArenaTagSide } from "#enums/arena-tag-side";
|
||||
import type { PokemonMove } from "#moves/pokemon-move";
|
||||
import { toHaveArenaTagOptions } from "#test/test-utils/matchers/to-have-arena-tag";
|
||||
import { toHavePositionalTagOptions } from "#test/test-utils/matchers/to-have-positional-tag";
|
||||
|
||||
declare module "vitest" {
|
||||
interface Assertion {
|
||||
interface Assertion<T> {
|
||||
/**
|
||||
* Check whether an array contains EXACTLY the given items (in any order).
|
||||
*
|
||||
@ -27,45 +36,9 @@ declare module "vitest" {
|
||||
* @param expected - The expected contents of the array, in any order
|
||||
* @see {@linkcode expect.arrayContaining}
|
||||
*/
|
||||
toEqualArrayUnsorted<E>(expected: E[]): void;
|
||||
toEqualArrayUnsorted(expected: T[]): void;
|
||||
|
||||
/**
|
||||
* Check whether a {@linkcode Pokemon}'s current typing includes the given types.
|
||||
*
|
||||
* @param expected - The expected types (in any order)
|
||||
* @param options - The options passed to the matcher
|
||||
*/
|
||||
toHaveTypes(expected: [PokemonType, ...PokemonType[]], options?: toHaveTypesOptions): void;
|
||||
|
||||
/**
|
||||
* Matcher to check the contents of a {@linkcode Pokemon}'s move history.
|
||||
*
|
||||
* @param expectedValue - The expected value; can be a {@linkcode MoveId} or a partially filled {@linkcode TurnMove}
|
||||
* containing the desired properties to check
|
||||
* @param index - The index of the move history entry to check, in order from most recent to least recent.
|
||||
* Default `0` (last used move)
|
||||
* @see {@linkcode Pokemon.getLastXMoves}
|
||||
*/
|
||||
toHaveUsedMove(expected: MoveId | AtLeastOne<TurnMove>, index?: number): void;
|
||||
|
||||
/**
|
||||
* Check whether a {@linkcode Pokemon}'s effective stat is as expected
|
||||
* (checked after all stat value modifications).
|
||||
*
|
||||
* @param stat - The {@linkcode EffectiveStat} to check
|
||||
* @param expectedValue - The expected value of {@linkcode stat}
|
||||
* @param options - (Optional) The {@linkcode ToHaveEffectiveStatMatcherOptions}
|
||||
* @remarks
|
||||
* If you want to check the stat **before** modifiers are applied, use {@linkcode Pokemon.getStat} instead.
|
||||
*/
|
||||
toHaveEffectiveStat(stat: EffectiveStat, expectedValue: number, options?: ToHaveEffectiveStatMatcherOptions): 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;
|
||||
// #region Arena Matchers
|
||||
|
||||
/**
|
||||
* Check whether the current {@linkcode WeatherType} is as expected.
|
||||
@ -80,9 +53,60 @@ declare module "vitest" {
|
||||
toHaveTerrain(expectedTerrainType: TerrainType): void;
|
||||
|
||||
/**
|
||||
* Check whether a {@linkcode Pokemon} is at full HP.
|
||||
* Check whether the current {@linkcode Arena} contains the given {@linkcode ArenaTag}.
|
||||
* @param expectedTag - A partially-filled {@linkcode ArenaTag} containing the desired properties
|
||||
*/
|
||||
toHaveFullHp(): void;
|
||||
toHaveArenaTag<A extends ArenaTagType>(expectedTag: toHaveArenaTagOptions<A>): 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(s) of the field} the tag should affect; default {@linkcode ArenaTagSide.BOTH}
|
||||
*/
|
||||
toHaveArenaTag(expectedType: ArenaTagType, side?: ArenaTagSide): void;
|
||||
|
||||
/**
|
||||
* Check whether the current {@linkcode Arena} contains the given {@linkcode PositionalTag}.
|
||||
* @param expectedTag - A partially-filled `PositionalTag` containing the desired properties
|
||||
*/
|
||||
toHavePositionalTag<P extends PositionalTagType>(expectedTag: toHavePositionalTagOptions<P>): void;
|
||||
/**
|
||||
* Check whether the current {@linkcode Arena} contains the given number of {@linkcode PositionalTag}s.
|
||||
* @param expectedType - The {@linkcode PositionalTagType} of the desired tag
|
||||
* @param count - The number of instances of {@linkcode expectedType} that should be active;
|
||||
* defaults to `1` and must be within the range `[0, 4]`
|
||||
*/
|
||||
toHavePositionalTag(expectedType: PositionalTagType, count?: number): 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`
|
||||
* @param options - The {@linkcode toHaveTypesOptions | options} passed to the matcher
|
||||
*/
|
||||
toHaveTypes(expectedTypes: PokemonType[], options?: toHaveTypesOptions): void;
|
||||
|
||||
/**
|
||||
* Check whether a {@linkcode Pokemon} has used a move matching the given criteria.
|
||||
* @param expectedMove - The {@linkcode MoveId} the Pokemon is expected to have used,
|
||||
* or a partially filled {@linkcode TurnMove} containing the desired properties to check
|
||||
* @param index - The index of the move history entry to check, in order from most recent to least recent; default `0`
|
||||
* @see {@linkcode Pokemon.getLastXMoves}
|
||||
*/
|
||||
toHaveUsedMove(expectedMove: MoveId | AtLeastOne<TurnMove>, index?: number): void;
|
||||
|
||||
/**
|
||||
* Check whether a {@linkcode Pokemon}'s effective stat is as expected
|
||||
* (checked after all stat value modifications).
|
||||
* @param stat - The {@linkcode EffectiveStat} to check
|
||||
* @param expectedValue - The expected value of {@linkcode stat}
|
||||
* @param options - The {@linkcode toHaveEffectiveStatOptions | options} passed to the matcher
|
||||
* @remarks
|
||||
* If you want to check the stat **before** modifiers are applied, use {@linkcode Pokemon.getStat} instead.
|
||||
*/
|
||||
toHaveEffectiveStat(stat: EffectiveStat, expectedValue: number, options?: toHaveEffectiveStatOptions): void;
|
||||
|
||||
/**
|
||||
* Check whether a {@linkcode Pokemon} has a specific {@linkcode StatusEffect | non-volatile status effect}.
|
||||
@ -106,7 +130,7 @@ declare module "vitest" {
|
||||
|
||||
/**
|
||||
* Check whether a {@linkcode Pokemon} has applied a specific {@linkcode AbilityId}.
|
||||
* @param expectedAbilityId - The expected {@linkcode AbilityId}
|
||||
* @param expectedAbilityId - The `AbilityId` to check for
|
||||
*/
|
||||
toHaveAbilityApplied(expectedAbilityId: AbilityId): void;
|
||||
|
||||
@ -116,24 +140,36 @@ 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 `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
|
||||
* When checking whether an enemy wild Pokemon is fainted, one must reference it in a variable _before_ the fainting effect occurs
|
||||
* as otherwise the Pokemon will be GC'ed and rendered `undefined`.
|
||||
* When checking whether an enemy wild Pokemon is fainted, one must store a reference to it in a variable _before_ the fainting effect occurs.
|
||||
* Otherwise, the Pokemon will be removed from the field and garbage collected.
|
||||
*/
|
||||
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 expectedValue - The {@linkcode MoveId} of the {@linkcode PokemonMove} that should have consumed PP
|
||||
* @param moveId - The `MoveId` corresponding to the {@linkcode PokemonMove} that should have consumed PP
|
||||
* @param ppUsed - The numerical amount of PP that should have been consumed,
|
||||
* or `all` to indicate the move should be _out_ of PP
|
||||
* @remarks
|
||||
* If the Pokemon's moveset has been set via {@linkcode Overrides.MOVESET_OVERRIDE}/{@linkcode Overrides.OPP_MOVESET_OVERRIDE},
|
||||
* does not contain {@linkcode expectedMove}
|
||||
* or contains the desired move more than once, this will fail the test.
|
||||
* If the Pokemon's moveset has been set via {@linkcode Overrides.MOVESET_OVERRIDE}/{@linkcode Overrides.OPP_MOVESET_OVERRIDE}
|
||||
* or does not contain exactly one copy of {@linkcode moveId}, this will fail the test.
|
||||
*/
|
||||
toHaveUsedPP(expectedMove: MoveId, ppUsed: number | "all"): void;
|
||||
toHaveUsedPP(moveId: MoveId, ppUsed: number | "all"): void;
|
||||
|
||||
// #endregion Pokemon Matchers
|
||||
}
|
||||
}
|
||||
|
@ -1,10 +1,12 @@
|
||||
import { toEqualArrayUnsorted } from "#test/test-utils/matchers/to-equal-array-unsorted";
|
||||
import { toHaveAbilityApplied } from "#test/test-utils/matchers/to-have-ability-applied";
|
||||
import { toHaveArenaTag } from "#test/test-utils/matchers/to-have-arena-tag";
|
||||
import { toHaveBattlerTag } from "#test/test-utils/matchers/to-have-battler-tag";
|
||||
import { toHaveEffectiveStat } from "#test/test-utils/matchers/to-have-effective-stat";
|
||||
import { toHaveFainted } from "#test/test-utils/matchers/to-have-fainted";
|
||||
import { toHaveFullHp } from "#test/test-utils/matchers/to-have-full-hp";
|
||||
import { toHaveHp } from "#test/test-utils/matchers/to-have-hp";
|
||||
import { toHavePositionalTag } from "#test/test-utils/matchers/to-have-positional-tag";
|
||||
import { toHaveStatStage } from "#test/test-utils/matchers/to-have-stat-stage";
|
||||
import { toHaveStatusEffect } from "#test/test-utils/matchers/to-have-status-effect";
|
||||
import { toHaveTakenDamage } from "#test/test-utils/matchers/to-have-taken-damage";
|
||||
@ -22,18 +24,20 @@ import { expect } from "vitest";
|
||||
|
||||
expect.extend({
|
||||
toEqualArrayUnsorted,
|
||||
toHaveWeather,
|
||||
toHaveTerrain,
|
||||
toHaveArenaTag,
|
||||
toHavePositionalTag,
|
||||
toHaveTypes,
|
||||
toHaveUsedMove,
|
||||
toHaveEffectiveStat,
|
||||
toHaveTakenDamage,
|
||||
toHaveWeather,
|
||||
toHaveTerrain,
|
||||
toHaveFullHp,
|
||||
toHaveStatusEffect,
|
||||
toHaveStatStage,
|
||||
toHaveBattlerTag,
|
||||
toHaveAbilityApplied,
|
||||
toHaveHp,
|
||||
toHaveTakenDamage,
|
||||
toHaveFullHp,
|
||||
toHaveFainted,
|
||||
toHaveUsedPP,
|
||||
});
|
||||
|
@ -1,4 +1,3 @@
|
||||
import { globalScene } from "#app/global-scene";
|
||||
import { Status } from "#data/status-effect";
|
||||
import { AbilityId } from "#enums/ability-id";
|
||||
import { BattleType } from "#enums/battle-type";
|
||||
@ -179,18 +178,13 @@ describe("Moves - Whirlwind", () => {
|
||||
const eligibleEnemy = enemyParty.filter(p => p.hp > 0 && p.isAllowedInBattle());
|
||||
expect(eligibleEnemy.length).toBe(1);
|
||||
|
||||
// Spy on the queueMessage function
|
||||
const queueSpy = vi.spyOn(globalScene.phaseManager, "queueMessage");
|
||||
|
||||
// Player uses Whirlwind; opponent uses Splash
|
||||
game.move.select(MoveId.WHIRLWIND);
|
||||
await game.move.selectEnemyMove(MoveId.SPLASH);
|
||||
await game.toNextTurn();
|
||||
|
||||
// Verify that the failure message is displayed for Whirlwind
|
||||
expect(queueSpy).toHaveBeenCalledWith(expect.stringContaining("But it failed"));
|
||||
// Verify the opponent's Splash message
|
||||
expect(queueSpy).toHaveBeenCalledWith(expect.stringContaining("But nothing happened!"));
|
||||
const player = game.field.getPlayerPokemon();
|
||||
expect(player).toHaveUsedMove({ move: MoveId.WHIRLWIND, result: MoveResult.FAIL });
|
||||
});
|
||||
|
||||
it("should not pull in the other trainer's pokemon in a partner trainer battle", async () => {
|
||||
|
@ -39,15 +39,6 @@ describe("Move - Wish", () => {
|
||||
.enemyLevel(100);
|
||||
});
|
||||
|
||||
/**
|
||||
* Expect that wish is active with the specified number of attacks.
|
||||
* @param numAttacks - The number of wish instances that should be queued; default `1`
|
||||
*/
|
||||
function expectWishActive(numAttacks = 1) {
|
||||
const wishes = game.scene.arena.positionalTagManager["tags"].filter(t => t.tagType === PositionalTagType.WISH);
|
||||
expect(wishes).toHaveLength(numAttacks);
|
||||
}
|
||||
|
||||
it("should heal the Pokemon in the current slot for 50% of the user's maximum HP", async () => {
|
||||
await game.classicMode.startBattle([SpeciesId.ALOMOMOLA, SpeciesId.BLISSEY]);
|
||||
|
||||
@ -58,19 +49,19 @@ describe("Move - Wish", () => {
|
||||
game.move.use(MoveId.WISH);
|
||||
await game.toNextTurn();
|
||||
|
||||
expectWishActive();
|
||||
expect(game).toHavePositionalTag(PositionalTagType.WISH);
|
||||
|
||||
game.doSwitchPokemon(1);
|
||||
await game.toEndOfTurn();
|
||||
|
||||
expectWishActive(0);
|
||||
expect(game).toHavePositionalTag(PositionalTagType.WISH, 0);
|
||||
expect(game.textInterceptor.logs).toContain(
|
||||
i18next.t("arenaTag:wishTagOnAdd", {
|
||||
pokemonNameWithAffix: getPokemonNameWithAffix(alomomola),
|
||||
}),
|
||||
);
|
||||
expect(alomomola.hp).toBe(1);
|
||||
expect(blissey.hp).toBe(toDmgValue(alomomola.getMaxHp() / 2) + 1);
|
||||
expect(alomomola).toHaveHp(1);
|
||||
expect(blissey).toHaveHp(toDmgValue(alomomola.getMaxHp() / 2) + 1);
|
||||
});
|
||||
|
||||
it("should work if the user has full HP, but not if it already has an active Wish", async () => {
|
||||
@ -82,13 +73,13 @@ describe("Move - Wish", () => {
|
||||
game.move.use(MoveId.WISH);
|
||||
await game.toNextTurn();
|
||||
|
||||
expectWishActive();
|
||||
expect(game).toHavePositionalTag(PositionalTagType.WISH);
|
||||
|
||||
game.move.use(MoveId.WISH);
|
||||
await game.toEndOfTurn();
|
||||
|
||||
expect(alomomola.hp).toBe(toDmgValue(alomomola.getMaxHp() / 2) + 1);
|
||||
expect(alomomola.getLastXMoves()[0].result).toBe(MoveResult.FAIL);
|
||||
expect(alomomola).toHaveUsedMove({ result: MoveResult.FAIL });
|
||||
});
|
||||
|
||||
it("should function independently of Future Sight", async () => {
|
||||
@ -103,7 +94,8 @@ describe("Move - Wish", () => {
|
||||
await game.setTurnOrder([BattlerIndex.ENEMY, BattlerIndex.PLAYER]);
|
||||
await game.toNextTurn();
|
||||
|
||||
expectWishActive(1);
|
||||
expect(game).toHavePositionalTag(PositionalTagType.WISH);
|
||||
expect(game).toHavePositionalTag(PositionalTagType.DELAYED_ATTACK);
|
||||
});
|
||||
|
||||
it("should work in double battles and trigger in order of creation", async () => {
|
||||
@ -127,7 +119,7 @@ describe("Move - Wish", () => {
|
||||
await game.setTurnOrder(oldOrder.map(p => p.getBattlerIndex()));
|
||||
await game.toNextTurn();
|
||||
|
||||
expectWishActive(4);
|
||||
expect(game).toHavePositionalTag(PositionalTagType.WISH, 4);
|
||||
|
||||
// Lower speed to change turn order
|
||||
alomomola.setStatStage(Stat.SPD, 6);
|
||||
@ -141,7 +133,7 @@ describe("Move - Wish", () => {
|
||||
await game.phaseInterceptor.to("PositionalTagPhase");
|
||||
|
||||
// all wishes have activated and added healing phases
|
||||
expectWishActive(0);
|
||||
expect(game).toHavePositionalTag(PositionalTagType.WISH, 0);
|
||||
|
||||
const healPhases = game.scene.phaseManager.phaseQueue.filter(p => p.is("PokemonHealPhase"));
|
||||
expect(healPhases).toHaveLength(4);
|
||||
@ -165,14 +157,14 @@ describe("Move - Wish", () => {
|
||||
game.move.use(MoveId.WISH, BattlerIndex.PLAYER_2);
|
||||
await game.toNextTurn();
|
||||
|
||||
expectWishActive();
|
||||
expect(game).toHavePositionalTag(PositionalTagType.WISH);
|
||||
|
||||
game.move.use(MoveId.SPLASH, BattlerIndex.PLAYER);
|
||||
game.move.use(MoveId.MEMENTO, BattlerIndex.PLAYER_2, BattlerIndex.ENEMY_2);
|
||||
await game.toEndOfTurn();
|
||||
|
||||
// Wish went away without doing anything
|
||||
expectWishActive(0);
|
||||
expect(game).toHavePositionalTag(PositionalTagType.WISH, 0);
|
||||
expect(game.textInterceptor.logs).not.toContain(
|
||||
i18next.t("arenaTag:wishTagOnAdd", {
|
||||
pokemonNameWithAffix: getPokemonNameWithAffix(blissey),
|
||||
|
@ -1,4 +1,5 @@
|
||||
import { getOnelineDiffStr } from "#test/test-utils/string-utils";
|
||||
import { receivedStr } from "#test/test-utils/test-utils";
|
||||
import type { MatcherState, SyncExpectationResult } from "@vitest/expect";
|
||||
|
||||
/**
|
||||
@ -14,22 +15,22 @@ export function toEqualArrayUnsorted(
|
||||
): SyncExpectationResult {
|
||||
if (!Array.isArray(received)) {
|
||||
return {
|
||||
pass: false,
|
||||
message: () => `Expected an array, but got ${this.utils.stringify(received)}!`,
|
||||
pass: this.isNot,
|
||||
message: () => `Expected to receive an array, but got ${receivedStr(received)}!`,
|
||||
};
|
||||
}
|
||||
|
||||
if (received.length !== expected.length) {
|
||||
return {
|
||||
pass: false,
|
||||
message: () => `Expected to receive array of length ${received.length}, but got ${expected.length} instead!`,
|
||||
actual: received,
|
||||
message: () => `Expected to receive an array of length ${received.length}, but got ${expected.length} instead!`,
|
||||
expected,
|
||||
actual: received,
|
||||
};
|
||||
}
|
||||
|
||||
const actualSorted = received.slice().sort();
|
||||
const expectedSorted = expected.slice().sort();
|
||||
const actualSorted = received.toSorted();
|
||||
const expectedSorted = expected.toSorted();
|
||||
const pass = this.equals(actualSorted, expectedSorted, [...this.customTesters, this.utils.iterableEquality]);
|
||||
|
||||
const actualStr = getOnelineDiffStr.call(this, actualSorted);
|
||||
|
@ -21,8 +21,8 @@ export function toHaveAbilityApplied(
|
||||
): SyncExpectationResult {
|
||||
if (!isPokemonInstance(received)) {
|
||||
return {
|
||||
pass: false,
|
||||
message: () => `Expected to recieve a Pokemon, but got ${receivedStr(received)}!`,
|
||||
pass: this.isNot,
|
||||
message: () => `Expected to receive a Pokemon, but got ${receivedStr(received)}!`,
|
||||
};
|
||||
}
|
||||
|
||||
|
77
test/test-utils/matchers/to-have-arena-tag.ts
Normal file
77
test/test-utils/matchers/to-have-arena-tag.ts
Normal file
@ -0,0 +1,77 @@
|
||||
import type { ArenaTag, ArenaTagTypeMap } from "#data/arena-tag";
|
||||
import type { ArenaTagSide } from "#enums/arena-tag-side";
|
||||
import type { ArenaTagType } from "#enums/arena-tag-type";
|
||||
import type { OneOther } from "#test/@types/test-helpers";
|
||||
// biome-ignore lint/correctness/noUnusedImports: TSDoc
|
||||
import type { GameManager } from "#test/test-utils/game-manager";
|
||||
import { getOnelineDiffStr } from "#test/test-utils/string-utils";
|
||||
import { isGameManagerInstance, receivedStr } from "#test/test-utils/test-utils";
|
||||
import type { MatcherState, SyncExpectationResult } from "@vitest/expect";
|
||||
|
||||
// intersection required to preserve T for inferences
|
||||
export type toHaveArenaTagOptions<T extends ArenaTagType> = OneOther<ArenaTagTypeMap[T], "tagType" | "side"> & {
|
||||
tagType: T;
|
||||
};
|
||||
|
||||
/**
|
||||
* Matcher to check if the {@linkcode Arena} has a given {@linkcode ArenaTag} active.
|
||||
* @param received - The object to check. Should be the current {@linkcode GameManager}.
|
||||
* @param expectedTag - The `ArenaTagType` of the desired tag, or a partially-filled object
|
||||
* containing the desired properties
|
||||
* @param side - The {@linkcode ArenaTagSide | side of the field} the tag should affect, or
|
||||
* {@linkcode ArenaTagSide.BOTH} to check both sides
|
||||
* @returns The result of the matching
|
||||
*/
|
||||
export function toHaveArenaTag<T extends ArenaTagType>(
|
||||
this: MatcherState,
|
||||
received: unknown,
|
||||
expectedTag: T | toHaveArenaTagOptions<T>,
|
||||
side?: ArenaTagSide,
|
||||
): SyncExpectationResult {
|
||||
if (!isGameManagerInstance(received)) {
|
||||
return {
|
||||
pass: this.isNot,
|
||||
message: () => `Expected to receive a GameManager, but got ${receivedStr(received)}!`,
|
||||
};
|
||||
}
|
||||
|
||||
if (!received.scene?.arena) {
|
||||
return {
|
||||
pass: this.isNot,
|
||||
message: () => `Expected GameManager.${received.scene ? "scene.arena" : "scene"} to be defined!`,
|
||||
};
|
||||
}
|
||||
|
||||
// Coerce lone `tagType`s into objects
|
||||
// Bangs are ok as we enforce safety via overloads
|
||||
// @ts-expect-error - Typescript is being stupid as tag type and side will always exist
|
||||
const etag: Partial<ArenaTag> & { tagType: T; side: ArenaTagSide } =
|
||||
typeof expectedTag === "object" ? expectedTag : { tagType: expectedTag, side: side! };
|
||||
|
||||
// We need to get all tags for the case of checking properties of a tag present on both sides of the arena
|
||||
const tags = received.scene.arena.findTagsOnSide(t => t.tagType === etag.tagType, etag.side);
|
||||
if (tags.length === 0) {
|
||||
return {
|
||||
pass: false,
|
||||
message: () => `Expected the Arena to have a tag of type ${etag.tagType}, but it didn't!`,
|
||||
expected: etag.tagType,
|
||||
actual: received.scene.arena.tags.map(t => t.tagType),
|
||||
};
|
||||
}
|
||||
|
||||
// Pass if any of the matching tags meet our criteria
|
||||
const pass = tags.some(tag =>
|
||||
this.equals(tag, expectedTag, [...this.customTesters, this.utils.subsetEquality, this.utils.iterableEquality]),
|
||||
);
|
||||
|
||||
const expectedStr = getOnelineDiffStr.call(this, expectedTag);
|
||||
return {
|
||||
pass,
|
||||
message: () =>
|
||||
pass
|
||||
? `Expected the Arena to NOT have a tag matching ${expectedStr}, but it did!`
|
||||
: `Expected the Arena to have a tag matching ${expectedStr}, but it didn't!`,
|
||||
expected: expectedTag,
|
||||
actual: tags,
|
||||
};
|
||||
}
|
@ -6,7 +6,7 @@ import { getStatName } from "#test/test-utils/string-utils";
|
||||
import { isPokemonInstance, receivedStr } from "#test/test-utils/test-utils";
|
||||
import type { MatcherState, SyncExpectationResult } from "@vitest/expect";
|
||||
|
||||
export interface ToHaveEffectiveStatMatcherOptions {
|
||||
export interface toHaveEffectiveStatOptions {
|
||||
/**
|
||||
* The target {@linkcode Pokemon}
|
||||
* @see {@linkcode Pokemon.getEffectiveStat}
|
||||
@ -30,7 +30,7 @@ export interface ToHaveEffectiveStatMatcherOptions {
|
||||
* @param received - The object to check. Should be a {@linkcode Pokemon}
|
||||
* @param stat - The {@linkcode EffectiveStat} to check
|
||||
* @param expectedValue - The expected value of the {@linkcode stat}
|
||||
* @param options - The {@linkcode ToHaveEffectiveStatMatcherOptions}
|
||||
* @param options - The {@linkcode toHaveEffectiveStatOptions}
|
||||
* @returns Whether the matcher passed
|
||||
*/
|
||||
export function toHaveEffectiveStat(
|
||||
@ -38,11 +38,11 @@ export function toHaveEffectiveStat(
|
||||
received: unknown,
|
||||
stat: EffectiveStat,
|
||||
expectedValue: number,
|
||||
{ enemy, move, isCritical = false }: ToHaveEffectiveStatMatcherOptions = {},
|
||||
{ enemy, move, isCritical = false }: toHaveEffectiveStatOptions = {},
|
||||
): SyncExpectationResult {
|
||||
if (!isPokemonInstance(received)) {
|
||||
return {
|
||||
pass: false,
|
||||
pass: this.isNot,
|
||||
message: () => `Expected to receive a Pokémon, but got ${receivedStr(received)}!`,
|
||||
};
|
||||
}
|
||||
|
@ -12,7 +12,7 @@ import type { MatcherState, SyncExpectationResult } from "@vitest/expect";
|
||||
export function toHaveFainted(this: MatcherState, received: unknown): SyncExpectationResult {
|
||||
if (!isPokemonInstance(received)) {
|
||||
return {
|
||||
pass: false,
|
||||
pass: this.isNot,
|
||||
message: () => `Expected to receive a Pokémon, but got ${receivedStr(received)}!`,
|
||||
};
|
||||
}
|
||||
|
@ -12,7 +12,7 @@ import type { MatcherState, SyncExpectationResult } from "@vitest/expect";
|
||||
export function toHaveFullHp(this: MatcherState, received: unknown): SyncExpectationResult {
|
||||
if (!isPokemonInstance(received)) {
|
||||
return {
|
||||
pass: false,
|
||||
pass: this.isNot,
|
||||
message: () => `Expected to receive a Pokémon, but got ${receivedStr(received)}!`,
|
||||
};
|
||||
}
|
||||
|
@ -13,7 +13,7 @@ import type { MatcherState, SyncExpectationResult } from "@vitest/expect";
|
||||
export function toHaveHp(this: MatcherState, received: unknown, expectedHp: number): SyncExpectationResult {
|
||||
if (!isPokemonInstance(received)) {
|
||||
return {
|
||||
pass: false,
|
||||
pass: this.isNot,
|
||||
message: () => `Expected to receive a Pokémon, but got ${receivedStr(received)}!`,
|
||||
};
|
||||
}
|
||||
|
107
test/test-utils/matchers/to-have-positional-tag.ts
Normal file
107
test/test-utils/matchers/to-have-positional-tag.ts
Normal file
@ -0,0 +1,107 @@
|
||||
// biome-ignore-start lint/correctness/noUnusedImports: TSDoc
|
||||
import type { GameManager } from "#test/test-utils/game-manager";
|
||||
// biome-ignore-end lint/correctness/noUnusedImports: TSDoc
|
||||
|
||||
import type { serializedPosTagMap } from "#data/positional-tags/load-positional-tag";
|
||||
import type { PositionalTagType } from "#enums/positional-tag-type";
|
||||
import type { OneOther } from "#test/@types/test-helpers";
|
||||
import { getOnelineDiffStr } from "#test/test-utils/string-utils";
|
||||
import { isGameManagerInstance, receivedStr } from "#test/test-utils/test-utils";
|
||||
import { toTitleCase } from "#utils/strings";
|
||||
import type { MatcherState, SyncExpectationResult } from "@vitest/expect";
|
||||
|
||||
export type toHavePositionalTagOptions<P extends PositionalTagType> = OneOther<serializedPosTagMap[P], "tagType"> & {
|
||||
tagType: P;
|
||||
};
|
||||
|
||||
/**
|
||||
* Matcher to check if the {@linkcode Arena} has a certain number of {@linkcode PositionalTag}s active.
|
||||
* @param received - The object to check. Should be the current {@linkcode GameManager}
|
||||
* @param expectedTag - The {@linkcode PositionalTagType} of the desired tag, or a partially-filled {@linkcode PositionalTag}
|
||||
* containing the desired properties
|
||||
* @param count - The number of tags that should be active; defaults to `1` and must be within the range `[0, 4]`
|
||||
* @returns The result of the matching
|
||||
*/
|
||||
export function toHavePositionalTag<P extends PositionalTagType>(
|
||||
this: MatcherState,
|
||||
received: unknown,
|
||||
expectedTag: P | toHavePositionalTagOptions<P>,
|
||||
count = 1,
|
||||
): SyncExpectationResult {
|
||||
if (!isGameManagerInstance(received)) {
|
||||
return {
|
||||
pass: this.isNot,
|
||||
message: () => `Expected to receive a GameManager, but got ${receivedStr(received)}!`,
|
||||
};
|
||||
}
|
||||
|
||||
if (!received.scene?.arena?.positionalTagManager) {
|
||||
return {
|
||||
pass: this.isNot,
|
||||
message: () =>
|
||||
`Expected GameManager.${received.scene?.arena ? "scene.arena.positionalTagManager" : received.scene ? "scene.arena" : "scene"} to be defined!`,
|
||||
};
|
||||
}
|
||||
|
||||
// TODO: Increase limit if triple battles are added
|
||||
if (count < 0 || count > 4) {
|
||||
return {
|
||||
pass: this.isNot,
|
||||
message: () => `Expected count to be between 0 and 4, but got ${count} instead!`,
|
||||
};
|
||||
}
|
||||
|
||||
const allTags = received.scene.arena.positionalTagManager.tags;
|
||||
const tagType = typeof expectedTag === "string" ? expectedTag : expectedTag.tagType;
|
||||
const matchingTags = allTags.filter(t => t.tagType === tagType);
|
||||
|
||||
// If checking exclusively tag type, check solely the number of matching tags on field
|
||||
if (typeof expectedTag === "string") {
|
||||
const pass = matchingTags.length === count;
|
||||
const expectedStr = getPosTagStr(expectedTag);
|
||||
|
||||
return {
|
||||
pass,
|
||||
message: () =>
|
||||
pass
|
||||
? `Expected the Arena to NOT have ${count} ${expectedStr} active, but it did!`
|
||||
: `Expected the Arena to have ${count} ${expectedStr} active, but got ${matchingTags.length} instead!`,
|
||||
expected: expectedTag,
|
||||
actual: allTags,
|
||||
};
|
||||
}
|
||||
|
||||
// Check for equality with the provided object
|
||||
if (matchingTags.length === 0) {
|
||||
return {
|
||||
pass: false,
|
||||
message: () => `Expected the Arena to have a tag of type ${expectedTag.tagType}, but it didn't!`,
|
||||
expected: expectedTag.tagType,
|
||||
actual: received.scene.arena.tags.map(t => t.tagType),
|
||||
};
|
||||
}
|
||||
|
||||
// Pass if any of the matching tags meet the criteria
|
||||
const pass = matchingTags.some(tag =>
|
||||
this.equals(tag, expectedTag, [...this.customTesters, this.utils.subsetEquality, this.utils.iterableEquality]),
|
||||
);
|
||||
|
||||
const expectedStr = getOnelineDiffStr.call(this, expectedTag);
|
||||
return {
|
||||
pass,
|
||||
message: () =>
|
||||
pass
|
||||
? `Expected the Arena to NOT have a tag matching ${expectedStr}, but it did!`
|
||||
: `Expected the Arena to have a tag matching ${expectedStr}, but it didn't!`,
|
||||
expected: expectedTag,
|
||||
actual: matchingTags,
|
||||
};
|
||||
}
|
||||
|
||||
function getPosTagStr(pType: PositionalTagType, count = 1): string {
|
||||
let ret = toTitleCase(pType) + "Tag";
|
||||
if (count > 1) {
|
||||
ret += "s";
|
||||
}
|
||||
return ret;
|
||||
}
|
@ -23,14 +23,14 @@ export function toHaveStatStage(
|
||||
): SyncExpectationResult {
|
||||
if (!isPokemonInstance(received)) {
|
||||
return {
|
||||
pass: false,
|
||||
pass: this.isNot,
|
||||
message: () => `Expected to receive a Pokémon, but got ${receivedStr(received)}!`,
|
||||
};
|
||||
}
|
||||
|
||||
if (expectedStage < -6 || expectedStage > 6) {
|
||||
return {
|
||||
pass: false,
|
||||
pass: this.isNot,
|
||||
message: () => `Expected ${expectedStage} to be within the range [-6, 6]!`,
|
||||
};
|
||||
}
|
||||
|
@ -28,7 +28,7 @@ export function toHaveStatusEffect(
|
||||
): SyncExpectationResult {
|
||||
if (!isPokemonInstance(received)) {
|
||||
return {
|
||||
pass: false,
|
||||
pass: this.isNot,
|
||||
message: () => `Expected to receive a Pokémon, but got ${receivedStr(received)}!`,
|
||||
};
|
||||
}
|
||||
@ -37,10 +37,8 @@ export function toHaveStatusEffect(
|
||||
const actualEffect = received.status?.effect ?? StatusEffect.NONE;
|
||||
|
||||
// Check exclusively effect equality first, coercing non-matching status effects to numbers.
|
||||
if (actualEffect !== (expectedStatus as Exclude<typeof expectedStatus, StatusEffect>)?.effect) {
|
||||
// This is actually 100% safe as `expectedStatus?.effect` will evaluate to `undefined` if a StatusEffect was passed,
|
||||
// which will never match actualEffect by definition
|
||||
expectedStatus = (expectedStatus as Exclude<typeof expectedStatus, StatusEffect>).effect;
|
||||
if (typeof expectedStatus === "object" && actualEffect !== expectedStatus.effect) {
|
||||
expectedStatus = expectedStatus.effect;
|
||||
}
|
||||
|
||||
if (typeof expectedStatus === "number") {
|
||||
|
@ -24,7 +24,7 @@ export function toHaveTakenDamage(
|
||||
): SyncExpectationResult {
|
||||
if (!isPokemonInstance(received)) {
|
||||
return {
|
||||
pass: false,
|
||||
pass: this.isNot,
|
||||
message: () => `Expected to receive a Pokémon, but got ${receivedStr(received)}!`,
|
||||
};
|
||||
}
|
||||
|
@ -20,15 +20,15 @@ export function toHaveTerrain(
|
||||
): SyncExpectationResult {
|
||||
if (!isGameManagerInstance(received)) {
|
||||
return {
|
||||
pass: false,
|
||||
message: () => `Expected GameManager, but got ${receivedStr(received)}!`,
|
||||
pass: this.isNot,
|
||||
message: () => `Expected to receive a GameManager, but got ${receivedStr(received)}!`,
|
||||
};
|
||||
}
|
||||
|
||||
if (!received.scene?.arena) {
|
||||
return {
|
||||
pass: false,
|
||||
message: () => `Expected GameManager.${received.scene ? "scene" : "scene.arena"} to be defined!`,
|
||||
pass: this.isNot,
|
||||
message: () => `Expected GameManager.${received.scene ? "scene.arena" : "scene"} to be defined!`,
|
||||
};
|
||||
}
|
||||
|
||||
@ -41,8 +41,8 @@ export function toHaveTerrain(
|
||||
pass,
|
||||
message: () =>
|
||||
pass
|
||||
? `Expected Arena to NOT have ${expectedStr} active, but it did!`
|
||||
: `Expected Arena to have ${expectedStr} active, but got ${actualStr} instead!`,
|
||||
? `Expected the Arena to NOT have ${expectedStr} active, but it did!`
|
||||
: `Expected the Arena to have ${expectedStr} active, but got ${actualStr} instead!`,
|
||||
expected: expectedTerrainType,
|
||||
actual,
|
||||
};
|
||||
|
@ -7,10 +7,16 @@ import { isPokemonInstance, receivedStr } from "../test-utils";
|
||||
|
||||
export interface toHaveTypesOptions {
|
||||
/**
|
||||
* Whether to enforce exact matches (`true`) or superset matches (`false`).
|
||||
* @defaultValue `true`
|
||||
* Value dictating the strength of the enforced typing match.
|
||||
*
|
||||
* Possible values (in ascending order of strength) are:
|
||||
* - `"ordered"`: Enforce that the {@linkcode Pokemon}'s types are identical **and in the same order**
|
||||
* - `"unordered"`: Enforce that the {@linkcode Pokemon}'s types are identical **without checking order**
|
||||
* - `"superset"`: Enforce that the {@linkcode Pokemon}'s types are **a superset of** the expected types
|
||||
* (all must be present, but extras can be there)
|
||||
* @defaultValue `"unordered"`
|
||||
*/
|
||||
exact?: boolean;
|
||||
mode?: "ordered" | "unordered" | "superset";
|
||||
/**
|
||||
* Optional arguments to pass to {@linkcode Pokemon.getTypes}.
|
||||
*/
|
||||
@ -18,35 +24,54 @@ export interface toHaveTypesOptions {
|
||||
}
|
||||
|
||||
/**
|
||||
* Matcher that checks if an array contains exactly the given items, disregarding order.
|
||||
* @param received - The object to check. Should be an array of one or more {@linkcode PokemonType}s.
|
||||
* @param options - The {@linkcode toHaveTypesOptions | options} for this matcher
|
||||
* Matcher that checks if a Pokemon's typing is as expected.
|
||||
* @param received - The object to check. Should be a {@linkcode Pokemon}
|
||||
* @param expectedTypes - An array of one or more {@linkcode PokemonType}s to compare against.
|
||||
* @param mode - The mode to perform the matching in.
|
||||
* Possible values (in ascending order of strength) are:
|
||||
* - `"ordered"`: Enforce that the {@linkcode Pokemon}'s types are identical **and in the same order**
|
||||
* - `"unordered"`: Enforce that the {@linkcode Pokemon}'s types are identical **without checking order**
|
||||
* - `"superset"`: Enforce that the {@linkcode Pokemon}'s types are **a superset of** the expected types
|
||||
* (all must be present, but extras can be there)
|
||||
*
|
||||
* Default `unordered`
|
||||
* @param args - Extra arguments passed to {@linkcode Pokemon.getTypes}
|
||||
* @returns The result of the matching
|
||||
*/
|
||||
export function toHaveTypes(
|
||||
this: MatcherState,
|
||||
received: unknown,
|
||||
expected: [PokemonType, ...PokemonType[]],
|
||||
options: toHaveTypesOptions = {},
|
||||
expectedTypes: [PokemonType, ...PokemonType[]],
|
||||
{ mode = "unordered", args = [] }: toHaveTypesOptions = {},
|
||||
): SyncExpectationResult {
|
||||
if (!isPokemonInstance(received)) {
|
||||
return {
|
||||
pass: false,
|
||||
message: () => `Expected to recieve a Pokémon, but got ${receivedStr(received)}!`,
|
||||
pass: this.isNot,
|
||||
message: () => `Expected to receive a Pokémon, but got ${receivedStr(received)}!`,
|
||||
};
|
||||
}
|
||||
|
||||
const actualTypes = received.getTypes(...(options.args ?? [])).sort();
|
||||
const expectedTypes = expected.slice().sort();
|
||||
// Return early if no types were passed in
|
||||
if (expectedTypes.length === 0) {
|
||||
return {
|
||||
pass: this.isNot,
|
||||
message: () => "Expected to receive a non-empty array of PokemonTypes!",
|
||||
};
|
||||
}
|
||||
|
||||
// Avoid sorting the types if strict ordering is desired
|
||||
const actualSorted = mode === "ordered" ? received.getTypes(...args) : received.getTypes(...args).toSorted();
|
||||
const expectedSorted = mode === "ordered" ? expectedTypes : expectedTypes.toSorted();
|
||||
|
||||
// Exact matches do not care about subset equality
|
||||
const matchers = options.exact
|
||||
? [...this.customTesters, this.utils.iterableEquality]
|
||||
: [...this.customTesters, this.utils.subsetEquality, this.utils.iterableEquality];
|
||||
const pass = this.equals(actualTypes, expectedTypes, matchers);
|
||||
const matchers =
|
||||
mode === "superset"
|
||||
? [...this.customTesters, this.utils.iterableEquality]
|
||||
: [...this.customTesters, this.utils.subsetEquality, this.utils.iterableEquality];
|
||||
const pass = this.equals(actualSorted, expectedSorted, matchers);
|
||||
|
||||
const actualStr = stringifyEnumArray(PokemonType, actualTypes);
|
||||
const expectedStr = stringifyEnumArray(PokemonType, expectedTypes);
|
||||
const actualStr = stringifyEnumArray(PokemonType, actualSorted);
|
||||
const expectedStr = stringifyEnumArray(PokemonType, expectedSorted);
|
||||
const pkmName = getPokemonNameWithAffix(received);
|
||||
|
||||
return {
|
||||
@ -55,7 +80,7 @@ export function toHaveTypes(
|
||||
pass
|
||||
? `Expected ${pkmName} to NOT have types ${expectedStr}, but it did!`
|
||||
: `Expected ${pkmName} to have types ${expectedStr}, but got ${actualStr} instead!`,
|
||||
expected: expectedTypes,
|
||||
actual: actualTypes,
|
||||
expected: expectedSorted,
|
||||
actual: actualSorted,
|
||||
};
|
||||
}
|
||||
|
@ -13,7 +13,7 @@ import type { MatcherState, SyncExpectationResult } from "@vitest/expect";
|
||||
/**
|
||||
* Matcher to check the contents of a {@linkcode Pokemon}'s move history.
|
||||
* @param received - The actual value received. Should be a {@linkcode Pokemon}
|
||||
* @param expectedValue - The {@linkcode MoveId} the Pokemon is expected to have used,
|
||||
* @param expectedMove - The {@linkcode MoveId} the Pokemon is expected to have used,
|
||||
* or a partially filled {@linkcode TurnMove} containing the desired properties to check
|
||||
* @param index - The index of the move history entry to check, in order from most recent to least recent.
|
||||
* Default `0` (last used move)
|
||||
@ -22,12 +22,12 @@ import type { MatcherState, SyncExpectationResult } from "@vitest/expect";
|
||||
export function toHaveUsedMove(
|
||||
this: MatcherState,
|
||||
received: unknown,
|
||||
expectedResult: MoveId | AtLeastOne<TurnMove>,
|
||||
expectedMove: MoveId | AtLeastOne<TurnMove>,
|
||||
index = 0,
|
||||
): SyncExpectationResult {
|
||||
if (!isPokemonInstance(received)) {
|
||||
return {
|
||||
pass: false,
|
||||
pass: this.isNot,
|
||||
message: () => `Expected to receive a Pokémon, but got ${receivedStr(received)}!`,
|
||||
};
|
||||
}
|
||||
@ -37,34 +37,33 @@ export function toHaveUsedMove(
|
||||
|
||||
if (move === undefined) {
|
||||
return {
|
||||
pass: false,
|
||||
pass: this.isNot,
|
||||
message: () => `Expected ${pkmName} to have used ${index + 1} moves, but it didn't!`,
|
||||
actual: received.getLastXMoves(-1),
|
||||
};
|
||||
}
|
||||
|
||||
// Coerce to a `TurnMove`
|
||||
if (typeof expectedResult === "number") {
|
||||
expectedResult = { move: expectedResult };
|
||||
if (typeof expectedMove === "number") {
|
||||
expectedMove = { move: expectedMove };
|
||||
}
|
||||
|
||||
const moveIndexStr = index === 0 ? "last move" : `${getOrdinal(index)} most recent move`;
|
||||
|
||||
const pass = this.equals(move, expectedResult, [
|
||||
const pass = this.equals(move, expectedMove, [
|
||||
...this.customTesters,
|
||||
this.utils.subsetEquality,
|
||||
this.utils.iterableEquality,
|
||||
]);
|
||||
|
||||
const expectedStr = getOnelineDiffStr.call(this, expectedResult);
|
||||
const expectedStr = getOnelineDiffStr.call(this, expectedMove);
|
||||
return {
|
||||
pass,
|
||||
message: () =>
|
||||
pass
|
||||
? `Expected ${pkmName}'s ${moveIndexStr} to NOT match ${expectedStr}, but it did!`
|
||||
: // Replace newlines with spaces to preserve one-line ness
|
||||
`Expected ${pkmName}'s ${moveIndexStr} to match ${expectedStr}, but it didn't!`,
|
||||
expected: expectedResult,
|
||||
: `Expected ${pkmName}'s ${moveIndexStr} to match ${expectedStr}, but it didn't!`,
|
||||
expected: expectedMove,
|
||||
actual: move,
|
||||
};
|
||||
}
|
||||
|
@ -13,7 +13,7 @@ import type { MatcherState, SyncExpectationResult } from "@vitest/expect";
|
||||
/**
|
||||
* Matcher to check the amount of PP consumed by a {@linkcode Pokemon}.
|
||||
* @param received - The actual value received. Should be a {@linkcode Pokemon}
|
||||
* @param expectedValue - The {@linkcode MoveId} that should have consumed PP
|
||||
* @param moveId - The {@linkcode MoveId} that should have consumed PP
|
||||
* @param ppUsed - The numerical amount of PP that should have been consumed,
|
||||
* or `all` to indicate the move should be _out_ of PP
|
||||
* @returns Whether the matcher passed
|
||||
@ -23,12 +23,12 @@ import type { MatcherState, SyncExpectationResult } from "@vitest/expect";
|
||||
export function toHaveUsedPP(
|
||||
this: MatcherState,
|
||||
received: unknown,
|
||||
expectedMove: MoveId,
|
||||
moveId: MoveId,
|
||||
ppUsed: number | "all",
|
||||
): SyncExpectationResult {
|
||||
if (!isPokemonInstance(received)) {
|
||||
return {
|
||||
pass: false,
|
||||
pass: this.isNot,
|
||||
message: () => `Expected to receive a Pokémon, but got ${receivedStr(received)}!`,
|
||||
};
|
||||
}
|
||||
@ -36,22 +36,22 @@ export function toHaveUsedPP(
|
||||
const override = received.isPlayer() ? Overrides.MOVESET_OVERRIDE : Overrides.OPP_MOVESET_OVERRIDE;
|
||||
if (coerceArray(override).length > 0) {
|
||||
return {
|
||||
pass: false,
|
||||
pass: this.isNot,
|
||||
message: () =>
|
||||
`Cannot test for PP consumption with ${received.isPlayer() ? "player" : "enemy"} moveset overrides active!`,
|
||||
};
|
||||
}
|
||||
|
||||
const pkmName = getPokemonNameWithAffix(received);
|
||||
const moveStr = getEnumStr(MoveId, expectedMove);
|
||||
const moveStr = getEnumStr(MoveId, moveId);
|
||||
|
||||
const movesetMoves = received.getMoveset().filter(pm => pm.moveId === expectedMove);
|
||||
const movesetMoves = received.getMoveset().filter(pm => pm.moveId === moveId);
|
||||
if (movesetMoves.length !== 1) {
|
||||
return {
|
||||
pass: false,
|
||||
pass: this.isNot,
|
||||
message: () =>
|
||||
`Expected MoveId.${moveStr} to appear in ${pkmName}'s moveset exactly once, but got ${movesetMoves.length} times!`,
|
||||
expected: expectedMove,
|
||||
expected: moveId,
|
||||
actual: received.getMoveset(),
|
||||
};
|
||||
}
|
||||
|
@ -20,15 +20,15 @@ export function toHaveWeather(
|
||||
): SyncExpectationResult {
|
||||
if (!isGameManagerInstance(received)) {
|
||||
return {
|
||||
pass: false,
|
||||
message: () => `Expected GameManager, but got ${receivedStr(received)}!`,
|
||||
pass: this.isNot,
|
||||
message: () => `Expected to receive a GameManager, but got ${receivedStr(received)}!`,
|
||||
};
|
||||
}
|
||||
|
||||
if (!received.scene?.arena) {
|
||||
return {
|
||||
pass: false,
|
||||
message: () => `Expected GameManager.${received.scene ? "scene" : "scene.arena"} to be defined!`,
|
||||
pass: this.isNot,
|
||||
message: () => `Expected GameManager.${received.scene ? "scene.arena" : "scene"} to be defined!`,
|
||||
};
|
||||
}
|
||||
|
||||
@ -41,8 +41,8 @@ export function toHaveWeather(
|
||||
pass,
|
||||
message: () =>
|
||||
pass
|
||||
? `Expected Arena to NOT have ${expectedStr} weather active, but it did!`
|
||||
: `Expected Arena to have ${expectedStr} weather active, but got ${actualStr} instead!`,
|
||||
? `Expected the Arena to NOT have ${expectedStr} weather active, but it did!`
|
||||
: `Expected the Arena to have ${expectedStr} weather active, but got ${actualStr} instead!`,
|
||||
expected: expectedWeatherType,
|
||||
actual,
|
||||
};
|
||||
|
@ -34,10 +34,10 @@ interface getEnumStrOptions {
|
||||
* @returns The stringified representation of `val` as dictated by the options.
|
||||
* @example
|
||||
* ```ts
|
||||
* enum fakeEnum {
|
||||
* ONE: 1,
|
||||
* TWO: 2,
|
||||
* THREE: 3,
|
||||
* enum testEnum {
|
||||
* ONE = 1,
|
||||
* TWO = 2,
|
||||
* THREE = 3,
|
||||
* }
|
||||
* getEnumStr(fakeEnum, fakeEnum.ONE); // Output: "ONE (=1)"
|
||||
* getEnumStr(fakeEnum, fakeEnum.TWO, {casing: "Title", prefix: "fakeEnum.", suffix: "!!!"}); // Output: "fakeEnum.TWO!!! (=2)"
|
||||
@ -174,10 +174,14 @@ export function getStatName(s: Stat): string {
|
||||
* Convert an object into a oneline diff to be shown in an error message.
|
||||
* @param obj - The object to return the oneline diff of
|
||||
* @returns The updated diff
|
||||
* @example
|
||||
* ```ts
|
||||
* const diff = getOnelineDiffStr.call(this, obj)
|
||||
* ```
|
||||
*/
|
||||
export function getOnelineDiffStr(this: MatcherState, obj: unknown): string {
|
||||
return this.utils
|
||||
.stringify(obj, undefined, { maxLength: 35, indent: 0, printBasicPrototype: false })
|
||||
.replace(/\n/g, " ") // Replace newlines with spaces
|
||||
.replace(/,(\s*)}$/g, "$1}");
|
||||
.replace(/,(\s*)}$/g, "$1}"); // Trim trailing commas
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user