mirror of
https://github.com/pagefaultgames/pokerogue.git
synced 2025-09-23 15:03:24 +02:00
Broke up the test matchers into multiple smaller interfaces
This commit is contained in:
parent
abe6dc4483
commit
ed02b7cbab
43
test/@types/vitest.d.ts
vendored
43
test/@types/vitest.d.ts
vendored
@ -13,6 +13,8 @@ import type { PokemonType } from "#enums/pokemon-type";
|
|||||||
import type { PositionalTagType } from "#enums/positional-tag-type";
|
import type { PositionalTagType } from "#enums/positional-tag-type";
|
||||||
import type { BattleStat, EffectiveStat } from "#enums/stat";
|
import type { BattleStat, EffectiveStat } from "#enums/stat";
|
||||||
import type { WeatherType } from "#enums/weather-type";
|
import type { WeatherType } from "#enums/weather-type";
|
||||||
|
import type { Pokemon } from "#field/pokemon";
|
||||||
|
import type { GameManager } from "#test/test-utils/game-manager";
|
||||||
import type { toHaveArenaTagOptions } from "#test/test-utils/matchers/to-have-arena-tag";
|
import type { toHaveArenaTagOptions } from "#test/test-utils/matchers/to-have-arena-tag";
|
||||||
import type { toHaveBattlerTagOptions } from "#test/test-utils/matchers/to-have-battler-tag";
|
import type { toHaveBattlerTagOptions } from "#test/test-utils/matchers/to-have-battler-tag";
|
||||||
import type { toHaveEffectiveStatOptions } from "#test/test-utils/matchers/to-have-effective-stat";
|
import type { toHaveEffectiveStatOptions } from "#test/test-utils/matchers/to-have-effective-stat";
|
||||||
@ -25,10 +27,15 @@ import type { AtLeastOne } from "#types/type-helpers";
|
|||||||
import type { toDmgValue } from "#utils/common";
|
import type { toDmgValue } from "#utils/common";
|
||||||
import type { expect } from "vitest";
|
import type { expect } from "vitest";
|
||||||
|
|
||||||
|
// #region Boilerplate
|
||||||
declare module "vitest" {
|
declare module "vitest" {
|
||||||
interface Assertion<T> {
|
interface Assertion<T> extends GenericMatchers<T>, GameManagerMatchers<T>, ArenaMatchers<T>, PokemonMatchers<T> {}
|
||||||
// #region Generic Matchers
|
}
|
||||||
|
|
||||||
|
// #endregion Boilerplate
|
||||||
|
|
||||||
|
// #region Generic Matchers
|
||||||
|
interface GenericMatchers<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).
|
||||||
*
|
*
|
||||||
@ -38,7 +45,7 @@ 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(expected: T[]): void;
|
toEqualArrayUnsorted(expected: T extends (infer U)[] ? U[] : never): void;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check whether a {@linkcode Map} contains the given key, disregarding its value.
|
* Check whether a {@linkcode Map} contains the given key, disregarding its value.
|
||||||
@ -49,12 +56,12 @@ declare module "vitest" {
|
|||||||
* `expect(x).toContain[y, expect.anything()]`,
|
* `expect(x).toContain[y, expect.anything()]`,
|
||||||
* this is still preferred due to being more ergonomic and provides better error messsages.
|
* this is still preferred due to being more ergonomic and provides better error messsages.
|
||||||
*/
|
*/
|
||||||
toHaveKey<E>(expectedKey: E): void;
|
toHaveKey(expectedKey: T extends Map<infer K, unknown> ? K : never): void;
|
||||||
|
}
|
||||||
// #endregion Generic Matchers
|
// #endregion Generic Matchers
|
||||||
|
|
||||||
// #region GameManager Matchers
|
|
||||||
|
|
||||||
|
// #region GameManager Matchers
|
||||||
|
interface GameManagerMatchers<_T> {
|
||||||
/**
|
/**
|
||||||
* Check if the {@linkcode GameManager} has shown the given message at least once in the current test case.
|
* Check if the {@linkcode GameManager} has shown the given message at least once in the current test case.
|
||||||
* @param expectedMessage - The expected message to be displayed
|
* @param expectedMessage - The expected message to be displayed
|
||||||
@ -69,10 +76,12 @@ declare module "vitest" {
|
|||||||
* @param expectedPhase - The expected {@linkcode PhaseString | name of the phase}
|
* @param expectedPhase - The expected {@linkcode PhaseString | name of the phase}
|
||||||
*/
|
*/
|
||||||
toBeAtPhase(expectedPhase: PhaseString): void;
|
toBeAtPhase(expectedPhase: PhaseString): void;
|
||||||
// #endregion GameManager Matchers
|
}
|
||||||
|
|
||||||
// #region Arena Matchers
|
// #endregion GameManager Matchers
|
||||||
|
|
||||||
|
// #region Arena Matchers
|
||||||
|
interface ArenaMatchers<_T> {
|
||||||
/**
|
/**
|
||||||
* Check whether the current {@linkcode WeatherType} is as expected.
|
* Check whether the current {@linkcode WeatherType} is as expected.
|
||||||
* @param expectedWeatherType - The expected {@linkcode WeatherType}
|
* @param expectedWeatherType - The expected {@linkcode WeatherType}
|
||||||
@ -109,11 +118,11 @@ declare module "vitest" {
|
|||||||
* defaults to `1` and must be within the range `[0, 4]`
|
* defaults to `1` and must be within the range `[0, 4]`
|
||||||
*/
|
*/
|
||||||
toHavePositionalTag(expectedType: PositionalTagType, count?: number): void;
|
toHavePositionalTag(expectedType: PositionalTagType, count?: number): void;
|
||||||
|
}
|
||||||
|
// #endregion Arena Matchers
|
||||||
|
|
||||||
// #endregion Arena Matchers
|
// #region Pokemon Matchers
|
||||||
|
interface PokemonMatchers<_T> {
|
||||||
// #region Pokemon Matchers
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 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 expectedTypes - The expected {@linkcode PokemonType}s to check against; must have length `>0`
|
||||||
@ -197,6 +206,7 @@ declare module "vitest" {
|
|||||||
* Check whether a {@linkcode Pokemon} is at full HP.
|
* Check whether a {@linkcode Pokemon} is at full HP.
|
||||||
*/
|
*/
|
||||||
toHaveFullHp(): void;
|
toHaveFullHp(): 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 moveId - The {@linkcode MoveId} corresponding to the {@linkcode PokemonMove} that should have consumed PP
|
* @param moveId - The {@linkcode MoveId} corresponding to the {@linkcode PokemonMove} that should have consumed PP
|
||||||
@ -207,7 +217,6 @@ declare module "vitest" {
|
|||||||
* or does not contain exactly one copy of `moveId`, this will fail the test.
|
* or does not contain exactly one copy of `moveId`, this will fail the test.
|
||||||
*/
|
*/
|
||||||
toHaveUsedPP(moveId: MoveId, ppUsed: number | "all"): void;
|
toHaveUsedPP(moveId: MoveId, ppUsed: number | "all"): void;
|
||||||
|
|
||||||
// #endregion Pokemon Matchers
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// #endregion Pokemon Matchers
|
||||||
|
@ -8,8 +8,8 @@ import { isGameManagerInstance, receivedStr } from "#test/test-utils/test-utils"
|
|||||||
import type { MatcherState, SyncExpectationResult } from "@vitest/expect";
|
import type { MatcherState, SyncExpectationResult } from "@vitest/expect";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Matcher that checks if the {@linkcode TerrainType} is as expected
|
* Matcher that checks if the current {@linkcode TerrainType} is as expected.
|
||||||
* @param received - The object to check. Should be an instance of {@linkcode GameManager}.
|
* @param received - The object to check. Should be the current {@linkcode GameManager}.
|
||||||
* @param expectedTerrainType - The expected {@linkcode TerrainType}, or {@linkcode TerrainType.NONE} if no terrain should be active
|
* @param expectedTerrainType - The expected {@linkcode TerrainType}, or {@linkcode TerrainType.NONE} if no terrain should be active
|
||||||
* @returns Whether the matcher passed
|
* @returns Whether the matcher passed
|
||||||
*/
|
*/
|
||||||
|
@ -8,8 +8,8 @@ import { toTitleCase } from "#utils/strings";
|
|||||||
import type { MatcherState, SyncExpectationResult } from "@vitest/expect";
|
import type { MatcherState, SyncExpectationResult } from "@vitest/expect";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Matcher that checks if the {@linkcode WeatherType} is as expected
|
* Matcher that checks if the current {@linkcode WeatherType} is as expected.
|
||||||
* @param received - The object to check. Expects an instance of {@linkcode GameManager}.
|
* @param received - The object to check. Should be the current {@linkcode GameManager}
|
||||||
* @param expectedWeatherType - The expected {@linkcode WeatherType}
|
* @param expectedWeatherType - The expected {@linkcode WeatherType}
|
||||||
* @returns Whether the matcher passed
|
* @returns Whether the matcher passed
|
||||||
*/
|
*/
|
||||||
|
Loading…
Reference in New Issue
Block a user