mirror of
https://github.com/pagefaultgames/pokerogue.git
synced 2025-12-24 10:39:15 +01:00
[Test] Cache arena tag matcher types; fix BattlerTag matcher distributiveness (#6821)
This commit is contained in:
parent
4545f9aae3
commit
49d89d469a
@ -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<A extends ArenaTagType> = OneOther<
|
||||
A extends SerializableArenaTagType ? ArenaTagDataMap[A] : ArenaTagTypeMap[A],
|
||||
"tagType" | "side"
|
||||
> & {
|
||||
type SerializableArenaTagOptions<A extends SerializableArenaTagType> = OneOther<ArenaTagDataMap[A], "tagType"> & {
|
||||
tagType: A;
|
||||
};
|
||||
|
||||
/**
|
||||
* Helper type for non-serializable arena tag options.
|
||||
* Allows for caching to avoid repeated instantiation and faster typechecking.
|
||||
* @internal
|
||||
*/
|
||||
type NonSerializableArenaTagOptions<A extends ArenaTagType> = OneOther<ArenaTagTypeMap[A], "tagType"> & {
|
||||
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 ArenaTagType> = [A] extends [SerializableArenaTagType]
|
||||
? SerializableArenaTagOptions<A>
|
||||
: NonSerializableArenaTagOptions<A>;
|
||||
|
||||
/**
|
||||
* 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
|
||||
|
||||
@ -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<B extends SerializableBattlerTagType> = OneOther<BattlerTagDataMap[B], "tagType"> & {
|
||||
type SerializableBattlerTagOptions<B extends SerializableBattlerTagType> = OneOther<BattlerTagDataMap[B], "tagType"> & {
|
||||
tagType: B;
|
||||
};
|
||||
|
||||
/**
|
||||
* Helper type for non-serializable battler tag options.
|
||||
* Allows for caching to avoid repeated instantiation and faster typechecking.
|
||||
* @internal
|
||||
*/
|
||||
type NonSerializableTagOptions<B extends BattlerTagType> = OneOther<BattlerTagTypeMap[B], "tagType"> & {
|
||||
type NonSerializableBattlerTagOptions<B extends BattlerTagType> = OneOther<BattlerTagTypeMap[B], "tagType"> & {
|
||||
tagType: B;
|
||||
};
|
||||
|
||||
@ -34,9 +33,9 @@ type NonSerializableTagOptions<B extends BattlerTagType> = OneOther<BattlerTagTy
|
||||
* If B corresponds to a serializable `BattlerTag`, only properties allowed to be serialized
|
||||
* (i.e. can change across instances) will be present and able to be checked.
|
||||
*/
|
||||
export type toHaveBattlerTagOptions<B extends BattlerTagType> = B extends SerializableBattlerTagType
|
||||
? SerializableTagOptions<B>
|
||||
: NonSerializableTagOptions<B>;
|
||||
export type toHaveBattlerTagOptions<B extends BattlerTagType> = [B] extends [SerializableBattlerTagType]
|
||||
? SerializableBattlerTagOptions<B>
|
||||
: NonSerializableBattlerTagOptions<B>;
|
||||
|
||||
/**
|
||||
* Matcher that checks if a {@linkcode Pokemon} has a specific {@linkcode BattlerTag}.
|
||||
|
||||
Loading…
Reference in New Issue
Block a user