From 49d89d469afb360fc5d0e907534888cd31a9a3d7 Mon Sep 17 00:00:00 2001 From: Bertie690 <136088738+Bertie690@users.noreply.github.com> Date: Thu, 18 Dec 2025 21:52:23 -0500 Subject: [PATCH] [Test] Cache arena tag matcher types; fix `BattlerTag` matcher distributiveness (#6821) --- test/test-utils/matchers/to-have-arena-tag.ts | 35 +++++++++++++------ .../matchers/to-have-battler-tag.ts | 17 +++++---- 2 files changed, 33 insertions(+), 19 deletions(-) diff --git a/test/test-utils/matchers/to-have-arena-tag.ts b/test/test-utils/matchers/to-have-arena-tag.ts index f54a4365912..dbf74b27242 100644 --- a/test/test-utils/matchers/to-have-arena-tag.ts +++ b/test/test-utils/matchers/to-have-arena-tag.ts @@ -9,22 +9,37 @@ import type { ArenaTagDataMap, SerializableArenaTagType } from "#types/arena-tag import type { MatcherState, SyncExpectationResult } from "@vitest/expect"; /** - * Options type for {@linkcode toHaveArenaTag}. - * @typeParam A - The {@linkcode ArenaTagType} being checked - * @remarks - * If A corresponds to a serializable `ArenaTag`, only properties allowed to be serialized - * (i.e. can change across instances) will be present and able to be checked. + * Helper type for serializable arena tag options. + * Allows for caching to avoid repeated instantiation and faster typechecking. + * @internal */ -export type toHaveArenaTagOptions = OneOther< - A extends SerializableArenaTagType ? ArenaTagDataMap[A] : ArenaTagTypeMap[A], - "tagType" | "side" -> & { +type SerializableArenaTagOptions = OneOther & { tagType: A; }; +/** + * Helper type for non-serializable arena tag options. + * Allows for caching to avoid repeated instantiation and faster typechecking. + * @internal + */ +type NonSerializableArenaTagOptions = OneOther & { + tagType: A; +}; + +/** + * Options type for {@linkcode toHaveArenaTag}. + * @typeParam A - The {@linkcode ArenaTagType} being checked + * @remarks + * If `A` corresponds to a serializable `ArenaTag`, only properties allowed to be serialized + * (i.e. can change across instances) will be present and able to be checked. + */ +export type toHaveArenaTagOptions = [A] extends [SerializableArenaTagType] + ? SerializableArenaTagOptions + : NonSerializableArenaTagOptions; + /** * 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 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 diff --git a/test/test-utils/matchers/to-have-battler-tag.ts b/test/test-utils/matchers/to-have-battler-tag.ts index 5f014247806..c8a8e39d2bd 100644 --- a/test/test-utils/matchers/to-have-battler-tag.ts +++ b/test/test-utils/matchers/to-have-battler-tag.ts @@ -8,22 +8,21 @@ import { isPokemonInstance, receivedStr } from "#test/test-utils/test-utils"; import type { BattlerTagDataMap, SerializableBattlerTagType } from "#types/battler-tags"; import type { MatcherState, SyncExpectationResult } from "@vitest/expect"; -// intersection required to preserve T for inferences - /** - * Helper type for serializable battler tag options. Allows for caching of the type to avoid - * instantiation each time typescript encounters the type. (dramatically speeds up typechecking) + * Helper type for serializable battler tag options. + * Allows for caching to avoid repeated instantiation and faster typechecking. * @internal */ -type SerializableTagOptions = OneOther & { +type SerializableBattlerTagOptions = OneOther & { tagType: B; }; /** * Helper type for non-serializable battler tag options. + * Allows for caching to avoid repeated instantiation and faster typechecking. * @internal */ -type NonSerializableTagOptions = OneOther & { +type NonSerializableBattlerTagOptions = OneOther & { tagType: B; }; @@ -34,9 +33,9 @@ type NonSerializableTagOptions = OneOther = B extends SerializableBattlerTagType - ? SerializableTagOptions - : NonSerializableTagOptions; +export type toHaveBattlerTagOptions = [B] extends [SerializableBattlerTagType] + ? SerializableBattlerTagOptions + : NonSerializableBattlerTagOptions; /** * Matcher that checks if a {@linkcode Pokemon} has a specific {@linkcode BattlerTag}.