mirror of
https://github.com/pagefaultgames/pokerogue.git
synced 2025-09-23 15:03:24 +02:00
Added toHaveKey
matcher + fixed imports
This commit is contained in:
parent
207808f37d
commit
abe6dc4483
26
test/@types/vitest.d.ts
vendored
26
test/@types/vitest.d.ts
vendored
@ -1,7 +1,7 @@
|
|||||||
import "vitest";
|
import "vitest";
|
||||||
|
|
||||||
import type { Phase } from "#app/phase";
|
|
||||||
import type Overrides from "#app/overrides";
|
import type Overrides from "#app/overrides";
|
||||||
|
import type { Phase } from "#app/phase";
|
||||||
import type { ArenaTag } from "#data/arena-tag";
|
import type { ArenaTag } from "#data/arena-tag";
|
||||||
import type { TerrainType } from "#data/terrain";
|
import type { TerrainType } from "#data/terrain";
|
||||||
import type { AbilityId } from "#enums/ability-id";
|
import type { AbilityId } from "#enums/ability-id";
|
||||||
@ -14,6 +14,7 @@ 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 { 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 { toHaveEffectiveStatOptions } from "#test/test-utils/matchers/to-have-effective-stat";
|
import type { toHaveEffectiveStatOptions } from "#test/test-utils/matchers/to-have-effective-stat";
|
||||||
import type { toHavePositionalTagOptions } from "#test/test-utils/matchers/to-have-positional-tag";
|
import type { toHavePositionalTagOptions } from "#test/test-utils/matchers/to-have-positional-tag";
|
||||||
import type { expectedStatusType } from "#test/test-utils/matchers/to-have-status-effect";
|
import type { expectedStatusType } from "#test/test-utils/matchers/to-have-status-effect";
|
||||||
@ -23,7 +24,6 @@ import type { TurnMove } from "#types/turn-move";
|
|||||||
import type { AtLeastOne } from "#types/type-helpers";
|
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";
|
||||||
import type { toHaveBattlerTagOptions } from "#test/test-utils/matchers/to-have-battler-tag";
|
|
||||||
|
|
||||||
declare module "vitest" {
|
declare module "vitest" {
|
||||||
interface Assertion<T> {
|
interface Assertion<T> {
|
||||||
@ -40,17 +40,33 @@ declare module "vitest" {
|
|||||||
*/
|
*/
|
||||||
toEqualArrayUnsorted(expected: T[]): void;
|
toEqualArrayUnsorted(expected: T[]): void;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check whether a {@linkcode Map} contains the given key, disregarding its value.
|
||||||
|
* @param expectedKey - The key whose inclusion is being checked
|
||||||
|
* @privateRemarks
|
||||||
|
* While this functionality _could_ be simulated by writing
|
||||||
|
* `expect(x.get(y)).toBeDefined()` or
|
||||||
|
* `expect(x).toContain[y, expect.anything()]`,
|
||||||
|
* this is still preferred due to being more ergonomic and provides better error messsages.
|
||||||
|
*/
|
||||||
|
toHaveKey<E>(expectedKey: E): void;
|
||||||
|
|
||||||
// #endregion Generic Matchers
|
// #endregion Generic Matchers
|
||||||
|
|
||||||
// #region GameManager Matchers
|
// #region GameManager Matchers
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check if the {@linkcode GameManager} has shown the given message at least once in the current battle.
|
* Check if the {@linkcode GameManager} has shown the given message at least once in the current test case.
|
||||||
* @param expectedMessage - The expected message
|
* @param expectedMessage - The expected message to be displayed
|
||||||
|
* @remarks
|
||||||
|
* Strings consumed by this function should _always_ be produced by a call to `i18n.t`
|
||||||
|
* to avoid hardcoding text into test files.
|
||||||
*/
|
*/
|
||||||
toHaveShownMessage(expectedMessage: string): void;
|
toHaveShownMessage(expectedMessage: string): void;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param expectedPhase - The expected {@linkcode PhaseString}
|
* Check if the currently-running {@linkcode Phase} is of the given type.
|
||||||
|
* @param expectedPhase - The expected {@linkcode PhaseString | name of the phase}
|
||||||
*/
|
*/
|
||||||
toBeAtPhase(expectedPhase: PhaseString): void;
|
toBeAtPhase(expectedPhase: PhaseString): void;
|
||||||
// #endregion GameManager Matchers
|
// #endregion GameManager Matchers
|
||||||
|
@ -7,6 +7,7 @@ import { toHaveEffectiveStat } from "#test/test-utils/matchers/to-have-effective
|
|||||||
import { toHaveFainted } from "#test/test-utils/matchers/to-have-fainted";
|
import { toHaveFainted } from "#test/test-utils/matchers/to-have-fainted";
|
||||||
import { toHaveFullHp } from "#test/test-utils/matchers/to-have-full-hp";
|
import { toHaveFullHp } from "#test/test-utils/matchers/to-have-full-hp";
|
||||||
import { toHaveHp } from "#test/test-utils/matchers/to-have-hp";
|
import { toHaveHp } from "#test/test-utils/matchers/to-have-hp";
|
||||||
|
import { toHaveKey } from "#test/test-utils/matchers/to-have-key";
|
||||||
import { toHavePositionalTag } from "#test/test-utils/matchers/to-have-positional-tag";
|
import { toHavePositionalTag } from "#test/test-utils/matchers/to-have-positional-tag";
|
||||||
import { toHaveShownMessage } from "#test/test-utils/matchers/to-have-shown-message";
|
import { toHaveShownMessage } from "#test/test-utils/matchers/to-have-shown-message";
|
||||||
import { toHaveStatStage } from "#test/test-utils/matchers/to-have-stat-stage";
|
import { toHaveStatStage } from "#test/test-utils/matchers/to-have-stat-stage";
|
||||||
@ -19,13 +20,15 @@ import { toHaveUsedPP } from "#test/test-utils/matchers/to-have-used-pp";
|
|||||||
import { toHaveWeather } from "#test/test-utils/matchers/to-have-weather";
|
import { toHaveWeather } from "#test/test-utils/matchers/to-have-weather";
|
||||||
import { expect } from "vitest";
|
import { expect } from "vitest";
|
||||||
|
|
||||||
/*
|
/**
|
||||||
|
* @module
|
||||||
* Setup file for custom matchers.
|
* Setup file for custom matchers.
|
||||||
* Make sure to define the call signatures in `#test/@types/vitest.d.ts` too!
|
* Make sure to define the call signatures in `#test/@types/vitest.d.ts` too!
|
||||||
*/
|
*/
|
||||||
|
|
||||||
expect.extend({
|
expect.extend({
|
||||||
toEqualArrayUnsorted,
|
toEqualArrayUnsorted,
|
||||||
|
toHaveKey,
|
||||||
toHaveShownMessage,
|
toHaveShownMessage,
|
||||||
toBeAtPhase,
|
toBeAtPhase,
|
||||||
toHaveWeather,
|
toHaveWeather,
|
||||||
|
@ -40,10 +40,7 @@ export class ModifierHelper extends GameManagerHelper {
|
|||||||
* @returns `this`
|
* @returns `this`
|
||||||
*/
|
*/
|
||||||
testCheck(modifier: ModifierTypeKeys, expectToBePreset: boolean): this {
|
testCheck(modifier: ModifierTypeKeys, expectToBePreset: boolean): this {
|
||||||
if (expectToBePreset) {
|
(expectToBePreset ? expect(itemPoolChecks) : expect(itemPoolChecks).not).toHaveKey(modifier);
|
||||||
expect(itemPoolChecks.get(modifier)).toBeTruthy();
|
|
||||||
}
|
|
||||||
expect(itemPoolChecks.get(modifier)).toBeFalsy();
|
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
47
test/test-utils/matchers/to-have-key.ts
Normal file
47
test/test-utils/matchers/to-have-key.ts
Normal file
@ -0,0 +1,47 @@
|
|||||||
|
import { getOnelineDiffStr } from "#test/test-utils/string-utils";
|
||||||
|
import { receivedStr } from "#test/test-utils/test-utils";
|
||||||
|
import type { MatcherState, SyncExpectationResult } from "@vitest/expect";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Matcher that checks if a {@linkcode Map} contains the given key, regardless of its value.
|
||||||
|
* @param received - The received value. Should be a Map
|
||||||
|
* @param expectedKey - The key whose inclusion in the map is being checked
|
||||||
|
* @returns Whether the matcher passed
|
||||||
|
*/
|
||||||
|
export function toHaveKey(this: MatcherState, received: unknown, expectedKey: unknown): SyncExpectationResult {
|
||||||
|
if (!(received instanceof Map)) {
|
||||||
|
return {
|
||||||
|
pass: this.isNot,
|
||||||
|
message: () => `Expected to receive a Map, but got ${receivedStr(received)}!`,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
if (received.size === 0) {
|
||||||
|
return {
|
||||||
|
pass: false,
|
||||||
|
message: () => "Expected to receive a non-empty Map, but received map was empty!",
|
||||||
|
expected: expectedKey,
|
||||||
|
actual: received,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
const keys = [...received.values()];
|
||||||
|
const pass = this.equals(keys, expectedKey, [
|
||||||
|
...this.customTesters,
|
||||||
|
this.utils.iterableEquality,
|
||||||
|
this.utils.subsetEquality,
|
||||||
|
]);
|
||||||
|
|
||||||
|
const actualStr = getOnelineDiffStr.call(this, received);
|
||||||
|
const expectedStr = getOnelineDiffStr.call(this, expectedKey);
|
||||||
|
|
||||||
|
return {
|
||||||
|
pass,
|
||||||
|
message: () =>
|
||||||
|
pass
|
||||||
|
? `Expected ${actualStr} to NOT have the key ${expectedStr}, but it did!`
|
||||||
|
: `Expected ${actualStr} to have the key ${expectedStr}, but it didn't!`,
|
||||||
|
expected: expectedKey,
|
||||||
|
actual: keys,
|
||||||
|
};
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user