mirror of
https://github.com/pagefaultgames/pokerogue.git
synced 2025-08-09 17:09:26 +02:00
More semantic changes
This commit is contained in:
parent
9455030fbe
commit
df8d1dc8c7
47
test/@types/vitest.d.ts
vendored
47
test/@types/vitest.d.ts
vendored
@ -24,7 +24,7 @@ import type { PokemonMove } from "#moves/pokemon-move";
|
|||||||
import type { OneOther } from "#test/@types/test-helpers";
|
import type { OneOther } from "#test/@types/test-helpers";
|
||||||
|
|
||||||
declare module "vitest" {
|
declare module "vitest" {
|
||||||
interface Assertion {
|
interface Assertion<T> {
|
||||||
/**
|
/**
|
||||||
* Check whether an array contains EXACTLY the given items (in any order).
|
* Check whether an array contains EXACTLY the given items (in any order).
|
||||||
*
|
*
|
||||||
@ -34,38 +34,28 @@ declare module "vitest" {
|
|||||||
* @param expected - The expected contents of the array, in any order
|
* @param expected - The expected contents of the array, in any order
|
||||||
* @see {@linkcode expect.arrayContaining}
|
* @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.
|
* 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 expected - The expected types (in any order)
|
|
||||||
* @param options - The {@linkcode toHaveTypesOptions | options} passed to the matcher
|
* @param options - The {@linkcode toHaveTypesOptions | options} passed to the matcher
|
||||||
*/
|
*/
|
||||||
toHaveTypes(expected: [PokemonType, ...PokemonType[]], options?: toHaveTypesOptions): void;
|
toHaveTypes(expectedTypes: PokemonType[], options?: toHaveTypesOptions): void;
|
||||||
/**
|
|
||||||
* Check whether a {@linkcode Pokemon}'s current typing includes the given types.
|
|
||||||
*
|
|
||||||
* @param expected - The expected types (in any order)
|
|
||||||
* @param options - The {@linkcode toHaveTypesOptions | options} passed to the matcher
|
|
||||||
*/
|
|
||||||
toHaveTypes(expected: PokemonType[], options?: toHaveTypesOptions): void;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Matcher to check the contents of a {@linkcode Pokemon}'s move history.
|
* 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,
|
||||||
* @param expectedValue - The expected value; can be a {@linkcode MoveId} or a partially filled {@linkcode TurnMove}
|
* or a partially filled {@linkcode TurnMove} containing the desired properties to check
|
||||||
* 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.
|
* @param index - The index of the move history entry to check, in order from most recent to least recent.
|
||||||
* Default `0` (last used move)
|
* Default `0` (last used move)
|
||||||
* @see {@linkcode Pokemon.getLastXMoves}
|
* @see {@linkcode Pokemon.getLastXMoves}
|
||||||
*/
|
*/
|
||||||
toHaveUsedMove(expected: MoveId | AtLeastOne<TurnMove>, index?: number): void;
|
toHaveUsedMove(expectedMove: MoveId | AtLeastOne<TurnMove>, index?: number): void;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check whether a {@linkcode Pokemon}'s effective stat is as expected
|
* Check whether a {@linkcode Pokemon}'s effective stat is as expected
|
||||||
* (checked after all stat value modifications).
|
* (checked after all stat value modifications).
|
||||||
*
|
|
||||||
* @param stat - The {@linkcode EffectiveStat} to check
|
* @param stat - The {@linkcode EffectiveStat} to check
|
||||||
* @param expectedValue - The expected value of {@linkcode stat}
|
* @param expectedValue - The expected value of {@linkcode stat}
|
||||||
* @param options - The {@linkcode toHaveEffectiveStatOptions | options} passed to the matcher
|
* @param options - The {@linkcode toHaveEffectiveStatOptions | options} passed to the matcher
|
||||||
@ -95,15 +85,13 @@ declare module "vitest" {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Check whether the current {@linkcode Arena} contains the given {@linkcode ArenaTag}.
|
* Check whether the current {@linkcode Arena} contains the given {@linkcode ArenaTag}.
|
||||||
*
|
* @param expectedTag - A partially-filled {@linkcode ArenaTag} containing the desired properties
|
||||||
* @param expectedType - A partially-filled {@linkcode ArenaTag} containing the desired properties
|
|
||||||
*/
|
*/
|
||||||
toHaveArenaTag<T extends ArenaTagType>(
|
toHaveArenaTag<T extends ArenaTagType>(
|
||||||
expectedType: OneOther<ArenaTagTypeMap[T], "tagType" | "side"> & { tagType: T }, // intersection required to preserve T
|
expectedTag: OneOther<ArenaTagTypeMap[T], "tagType" | "side"> & { tagType: T }, // intersection required to preserve T
|
||||||
): void;
|
): void;
|
||||||
/**
|
/**
|
||||||
* Check whether the current {@linkcode Arena} contains the given {@linkcode ArenaTag}.
|
* Check whether the current {@linkcode Arena} contains the given {@linkcode ArenaTag}.
|
||||||
*
|
|
||||||
* @param expectedType - The {@linkcode ArenaTagType} of the desired tag
|
* @param expectedType - The {@linkcode ArenaTagType} of the desired tag
|
||||||
* @param side - The {@linkcode ArenaTagSide | side of the field} the tag should affect, or
|
* @param side - The {@linkcode ArenaTagSide | side of the field} the tag should affect, or
|
||||||
* {@linkcode ArenaTagSide.BOTH} to check both sides;
|
* {@linkcode ArenaTagSide.BOTH} to check both sides;
|
||||||
@ -138,7 +126,7 @@ declare module "vitest" {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Check whether a {@linkcode Pokemon} has applied a specific {@linkcode AbilityId}.
|
* Check whether a {@linkcode Pokemon} has applied a specific {@linkcode AbilityId}.
|
||||||
* @param expectedAbilityId - The expected {@linkcode AbilityId}
|
* @param expectedAbilityId - The expected {@linkcode AbilityId} to
|
||||||
*/
|
*/
|
||||||
toHaveAbilityApplied(expectedAbilityId: AbilityId): void;
|
toHaveAbilityApplied(expectedAbilityId: AbilityId): void;
|
||||||
|
|
||||||
@ -151,21 +139,20 @@ declare module "vitest" {
|
|||||||
/**
|
/**
|
||||||
* Check whether a {@linkcode Pokemon} is currently fainted (as determined by {@linkcode Pokemon.isFainted}).
|
* Check whether a {@linkcode Pokemon} is currently fainted (as determined by {@linkcode Pokemon.isFainted}).
|
||||||
* @remarks
|
* @remarks
|
||||||
* When checking whether an enemy wild Pokemon is fainted, one must reference it in a variable _before_ the fainting effect occurs
|
* When checking whether an enemy wild Pokemon is fainted, one must store a reference to it in a variable _before_ the fainting effect occurs,
|
||||||
* as otherwise the Pokemon will be GC'ed and rendered `undefined`.
|
* as otherwise the Pokemon will be removed from the field and garbage collected.
|
||||||
*/
|
*/
|
||||||
toHaveFainted(): void;
|
toHaveFainted(): void;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check whether a {@linkcode Pokemon} has consumed the given amount of PP for one of its moves.
|
* 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 {@linkcode MoveId} of the {@linkcode PokemonMove} that should have consumed PP
|
||||||
* @param ppUsed - The numerical amount of PP that should have been consumed,
|
* @param ppUsed - The numerical amount of PP that should have been consumed,
|
||||||
* or `all` to indicate the move should be _out_ of PP
|
* or `all` to indicate the move should be _out_ of PP
|
||||||
* @remarks
|
* @remarks
|
||||||
* If the Pokemon's moveset has been set via {@linkcode Overrides.MOVESET_OVERRIDE}/{@linkcode Overrides.OPP_MOVESET_OVERRIDE},
|
* If the Pokemon's moveset has been set via {@linkcode Overrides.MOVESET_OVERRIDE}/{@linkcode Overrides.OPP_MOVESET_OVERRIDE}
|
||||||
* does not contain {@linkcode expectedMove}
|
* or does not contain exactly 1 copy of {@linkcode moveId}, this will fail the test.
|
||||||
* or contains the desired move more than once, this will fail the test.
|
|
||||||
*/
|
*/
|
||||||
toHaveUsedPP(expectedMove: MoveId, ppUsed: number | "all"): void;
|
toHaveUsedPP(moveId: MoveId, ppUsed: number | "all"): void;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -21,7 +21,7 @@ export function toHaveAbilityApplied(
|
|||||||
): SyncExpectationResult {
|
): SyncExpectationResult {
|
||||||
if (!isPokemonInstance(received)) {
|
if (!isPokemonInstance(received)) {
|
||||||
return {
|
return {
|
||||||
pass: false,
|
pass: this.isNot,
|
||||||
message: () => `Expected to recieve a Pokemon, but got ${receivedStr(received)}!`,
|
message: () => `Expected to recieve a Pokemon, but got ${receivedStr(received)}!`,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -36,8 +36,8 @@ export function toHaveArenaTag<T extends ArenaTagType>(
|
|||||||
|
|
||||||
if (!received.scene?.arena) {
|
if (!received.scene?.arena) {
|
||||||
return {
|
return {
|
||||||
pass: false,
|
pass: this.isNot,
|
||||||
message: () => `Expected GameManager.${!received.scene ? "scene" : "scene.arena"} to be defined!`,
|
message: () => `Expected GameManager.${received.scene ? "scene.arena" : "scene"} to be defined!`,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -42,7 +42,7 @@ export function toHaveEffectiveStat(
|
|||||||
): SyncExpectationResult {
|
): SyncExpectationResult {
|
||||||
if (!isPokemonInstance(received)) {
|
if (!isPokemonInstance(received)) {
|
||||||
return {
|
return {
|
||||||
pass: false,
|
pass: this.isNot,
|
||||||
message: () => `Expected to receive a Pokémon, but got ${receivedStr(received)}!`,
|
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 {
|
export function toHaveFainted(this: MatcherState, received: unknown): SyncExpectationResult {
|
||||||
if (!isPokemonInstance(received)) {
|
if (!isPokemonInstance(received)) {
|
||||||
return {
|
return {
|
||||||
pass: false,
|
pass: this.isNot,
|
||||||
message: () => `Expected to receive a Pokémon, but got ${receivedStr(received)}!`,
|
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 {
|
export function toHaveFullHp(this: MatcherState, received: unknown): SyncExpectationResult {
|
||||||
if (!isPokemonInstance(received)) {
|
if (!isPokemonInstance(received)) {
|
||||||
return {
|
return {
|
||||||
pass: false,
|
pass: this.isNot,
|
||||||
message: () => `Expected to receive a Pokémon, but got ${receivedStr(received)}!`,
|
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 {
|
export function toHaveHp(this: MatcherState, received: unknown, expectedHp: number): SyncExpectationResult {
|
||||||
if (!isPokemonInstance(received)) {
|
if (!isPokemonInstance(received)) {
|
||||||
return {
|
return {
|
||||||
pass: false,
|
pass: this.isNot,
|
||||||
message: () => `Expected to receive a Pokémon, but got ${receivedStr(received)}!`,
|
message: () => `Expected to receive a Pokémon, but got ${receivedStr(received)}!`,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -23,14 +23,14 @@ export function toHaveStatStage(
|
|||||||
): SyncExpectationResult {
|
): SyncExpectationResult {
|
||||||
if (!isPokemonInstance(received)) {
|
if (!isPokemonInstance(received)) {
|
||||||
return {
|
return {
|
||||||
pass: false,
|
pass: this.isNot,
|
||||||
message: () => `Expected to receive a Pokémon, but got ${receivedStr(received)}!`,
|
message: () => `Expected to receive a Pokémon, but got ${receivedStr(received)}!`,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
if (expectedStage < -6 || expectedStage > 6) {
|
if (expectedStage < -6 || expectedStage > 6) {
|
||||||
return {
|
return {
|
||||||
pass: false,
|
pass: this.isNot,
|
||||||
message: () => `Expected ${expectedStage} to be within the range [-6, 6]!`,
|
message: () => `Expected ${expectedStage} to be within the range [-6, 6]!`,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -28,7 +28,7 @@ export function toHaveStatusEffect(
|
|||||||
): SyncExpectationResult {
|
): SyncExpectationResult {
|
||||||
if (!isPokemonInstance(received)) {
|
if (!isPokemonInstance(received)) {
|
||||||
return {
|
return {
|
||||||
pass: false,
|
pass: this.isNot,
|
||||||
message: () => `Expected to receive a Pokémon, but got ${receivedStr(received)}!`,
|
message: () => `Expected to receive a Pokémon, but got ${receivedStr(received)}!`,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -24,7 +24,7 @@ export function toHaveTakenDamage(
|
|||||||
): SyncExpectationResult {
|
): SyncExpectationResult {
|
||||||
if (!isPokemonInstance(received)) {
|
if (!isPokemonInstance(received)) {
|
||||||
return {
|
return {
|
||||||
pass: false,
|
pass: this.isNot,
|
||||||
message: () => `Expected to receive a Pokémon, but got ${receivedStr(received)}!`,
|
message: () => `Expected to receive a Pokémon, but got ${receivedStr(received)}!`,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -20,14 +20,14 @@ export function toHaveTerrain(
|
|||||||
): SyncExpectationResult {
|
): SyncExpectationResult {
|
||||||
if (!isGameManagerInstance(received)) {
|
if (!isGameManagerInstance(received)) {
|
||||||
return {
|
return {
|
||||||
pass: false,
|
pass: this.isNot,
|
||||||
message: () => `Expected to receive a GameManager, but got ${receivedStr(received)}!`,
|
message: () => `Expected to receive a GameManager, but got ${receivedStr(received)}!`,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!received.scene?.arena) {
|
if (!received.scene?.arena) {
|
||||||
return {
|
return {
|
||||||
pass: false,
|
pass: this.isNot,
|
||||||
message: () => `Expected GameManager.${received.scene ? "scene.arena" : "scene"} to be defined!`,
|
message: () => `Expected GameManager.${received.scene ? "scene.arena" : "scene"} to be defined!`,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -26,14 +26,14 @@ export interface toHaveTypesOptions {
|
|||||||
/**
|
/**
|
||||||
* Matcher that checks if a {@linkcode Pokemon}'s typing is as expected.
|
* Matcher that checks if a {@linkcode Pokemon}'s typing is as expected.
|
||||||
* @param received - The object to check. Should be a {@linkcode Pokemon}
|
* @param received - The object to check. Should be a {@linkcode Pokemon}
|
||||||
* @param expected - An array of one or more {@linkcode PokemonType}s to compare against.
|
* @param expectedTypes - An array of one or more {@linkcode PokemonType}s to compare against.
|
||||||
* @param mode - The mode to perform the matching;
|
* @param mode - The mode to perform the matching;
|
||||||
* @returns The result of the matching
|
* @returns The result of the matching
|
||||||
*/
|
*/
|
||||||
export function toHaveTypes(
|
export function toHaveTypes(
|
||||||
this: MatcherState,
|
this: MatcherState,
|
||||||
received: unknown,
|
received: unknown,
|
||||||
expected: [PokemonType, ...PokemonType[]],
|
expectedTypes: [PokemonType, ...PokemonType[]],
|
||||||
{ mode = "unordered", args = [] }: toHaveTypesOptions = {},
|
{ mode = "unordered", args = [] }: toHaveTypesOptions = {},
|
||||||
): SyncExpectationResult {
|
): SyncExpectationResult {
|
||||||
if (!isPokemonInstance(received)) {
|
if (!isPokemonInstance(received)) {
|
||||||
@ -43,19 +43,27 @@ export function toHaveTypes(
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Return early if no types were passed in
|
||||||
|
if (expectedTypes.length === 0) {
|
||||||
|
return {
|
||||||
|
pass: this.isNot,
|
||||||
|
message: () => "Expected to recieve a non-empty array of PokemonTypes, but got one!",
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
// Avoid sorting the types if strict ordering is desired
|
// Avoid sorting the types if strict ordering is desired
|
||||||
const actualTypes = mode === "ordered" ? received.getTypes(...args) : received.getTypes(...args).toSorted();
|
const actualSorted = mode === "ordered" ? received.getTypes(...args) : received.getTypes(...args).toSorted();
|
||||||
const expectedTypes = mode === "ordered" ? expected : expected.toSorted();
|
const expectedSorted = mode === "ordered" ? expectedTypes : expectedTypes.toSorted();
|
||||||
|
|
||||||
// Exact matches do not care about subset equality
|
// Exact matches do not care about subset equality
|
||||||
const matchers =
|
const matchers =
|
||||||
mode === "superset"
|
mode === "superset"
|
||||||
? [...this.customTesters, this.utils.iterableEquality]
|
? [...this.customTesters, this.utils.iterableEquality]
|
||||||
: [...this.customTesters, this.utils.subsetEquality, this.utils.iterableEquality];
|
: [...this.customTesters, this.utils.subsetEquality, this.utils.iterableEquality];
|
||||||
const pass = this.equals(actualTypes, expectedTypes, matchers);
|
const pass = this.equals(actualSorted, expectedSorted, matchers);
|
||||||
|
|
||||||
const actualStr = stringifyEnumArray(PokemonType, actualTypes);
|
const actualStr = stringifyEnumArray(PokemonType, actualSorted);
|
||||||
const expectedStr = stringifyEnumArray(PokemonType, expectedTypes);
|
const expectedStr = stringifyEnumArray(PokemonType, expectedSorted);
|
||||||
const pkmName = getPokemonNameWithAffix(received);
|
const pkmName = getPokemonNameWithAffix(received);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
@ -64,7 +72,7 @@ export function toHaveTypes(
|
|||||||
pass
|
pass
|
||||||
? `Expected ${pkmName} to NOT have types ${expectedStr}, but it did!`
|
? `Expected ${pkmName} to NOT have types ${expectedStr}, but it did!`
|
||||||
: `Expected ${pkmName} to have types ${expectedStr}, but got ${actualStr} instead!`,
|
: `Expected ${pkmName} to have types ${expectedStr}, but got ${actualStr} instead!`,
|
||||||
expected: expectedTypes,
|
expected: expectedSorted,
|
||||||
actual: actualTypes,
|
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.
|
* Matcher to check the contents of a {@linkcode Pokemon}'s move history.
|
||||||
* @param received - The actual value received. Should be a {@linkcode Pokemon}
|
* @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
|
* 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.
|
* @param index - The index of the move history entry to check, in order from most recent to least recent.
|
||||||
* Default `0` (last used move)
|
* Default `0` (last used move)
|
||||||
@ -22,7 +22,7 @@ import type { MatcherState, SyncExpectationResult } from "@vitest/expect";
|
|||||||
export function toHaveUsedMove(
|
export function toHaveUsedMove(
|
||||||
this: MatcherState,
|
this: MatcherState,
|
||||||
received: unknown,
|
received: unknown,
|
||||||
expectedResult: MoveId | AtLeastOne<TurnMove>,
|
expectedMove: MoveId | AtLeastOne<TurnMove>,
|
||||||
index = 0,
|
index = 0,
|
||||||
): SyncExpectationResult {
|
): SyncExpectationResult {
|
||||||
if (!isPokemonInstance(received)) {
|
if (!isPokemonInstance(received)) {
|
||||||
@ -44,26 +44,26 @@ export function toHaveUsedMove(
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Coerce to a `TurnMove`
|
// Coerce to a `TurnMove`
|
||||||
if (typeof expectedResult === "number") {
|
if (typeof expectedMove === "number") {
|
||||||
expectedResult = { move: expectedResult };
|
expectedMove = { move: expectedMove };
|
||||||
}
|
}
|
||||||
|
|
||||||
const moveIndexStr = index === 0 ? "last move" : `${getOrdinal(index)} most recent move`;
|
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.customTesters,
|
||||||
this.utils.subsetEquality,
|
this.utils.subsetEquality,
|
||||||
this.utils.iterableEquality,
|
this.utils.iterableEquality,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
const expectedStr = getOnelineDiffStr.call(this, expectedResult);
|
const expectedStr = getOnelineDiffStr.call(this, expectedMove);
|
||||||
return {
|
return {
|
||||||
pass,
|
pass,
|
||||||
message: () =>
|
message: () =>
|
||||||
pass
|
pass
|
||||||
? `Expected ${pkmName}'s ${moveIndexStr} to NOT match ${expectedStr}, but it did!`
|
? `Expected ${pkmName}'s ${moveIndexStr} to NOT match ${expectedStr}, but it did!`
|
||||||
: `Expected ${pkmName}'s ${moveIndexStr} to match ${expectedStr}, but it didn't!`,
|
: `Expected ${pkmName}'s ${moveIndexStr} to match ${expectedStr}, but it didn't!`,
|
||||||
expected: expectedResult,
|
expected: expectedMove,
|
||||||
actual: move,
|
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}.
|
* Matcher to check the amount of PP consumed by a {@linkcode Pokemon}.
|
||||||
* @param received - The actual value received. Should be 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,
|
* @param ppUsed - The numerical amount of PP that should have been consumed,
|
||||||
* or `all` to indicate the move should be _out_ of PP
|
* or `all` to indicate the move should be _out_ of PP
|
||||||
* @returns Whether the matcher passed
|
* @returns Whether the matcher passed
|
||||||
@ -23,7 +23,7 @@ import type { MatcherState, SyncExpectationResult } from "@vitest/expect";
|
|||||||
export function toHaveUsedPP(
|
export function toHaveUsedPP(
|
||||||
this: MatcherState,
|
this: MatcherState,
|
||||||
received: unknown,
|
received: unknown,
|
||||||
expectedMove: MoveId,
|
moveId: MoveId,
|
||||||
ppUsed: number | "all",
|
ppUsed: number | "all",
|
||||||
): SyncExpectationResult {
|
): SyncExpectationResult {
|
||||||
if (!isPokemonInstance(received)) {
|
if (!isPokemonInstance(received)) {
|
||||||
@ -43,15 +43,15 @@ export function toHaveUsedPP(
|
|||||||
}
|
}
|
||||||
|
|
||||||
const pkmName = getPokemonNameWithAffix(received);
|
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) {
|
if (movesetMoves.length !== 1) {
|
||||||
return {
|
return {
|
||||||
pass: this.isNot,
|
pass: this.isNot,
|
||||||
message: () =>
|
message: () =>
|
||||||
`Expected MoveId.${moveStr} to appear in ${pkmName}'s moveset exactly once, but got ${movesetMoves.length} times!`,
|
`Expected MoveId.${moveStr} to appear in ${pkmName}'s moveset exactly once, but got ${movesetMoves.length} times!`,
|
||||||
expected: expectedMove,
|
expected: moveId,
|
||||||
actual: received.getMoveset(),
|
actual: received.getMoveset(),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -174,10 +174,14 @@ export function getStatName(s: Stat): string {
|
|||||||
* Convert an object into a oneline diff to be shown in an error message.
|
* Convert an object into a oneline diff to be shown in an error message.
|
||||||
* @param obj - The object to return the oneline diff of
|
* @param obj - The object to return the oneline diff of
|
||||||
* @returns The updated diff
|
* @returns The updated diff
|
||||||
|
* @example
|
||||||
|
* ```ts
|
||||||
|
* const diff = getOnelineDiffStr.call(this, obj)
|
||||||
|
* ```
|
||||||
*/
|
*/
|
||||||
export function getOnelineDiffStr(this: MatcherState, obj: unknown): string {
|
export function getOnelineDiffStr(this: MatcherState, obj: unknown): string {
|
||||||
return this.utils
|
return this.utils
|
||||||
.stringify(obj, undefined, { maxLength: 35, indent: 0, printBasicPrototype: false })
|
.stringify(obj, undefined, { maxLength: 35, indent: 0, printBasicPrototype: false })
|
||||||
.replace(/\n/g, " ") // Replace newlines with spaces
|
.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