pokerogue/test/test-utils/helpers/modifiers-helper.ts
Bertie690 1691951c87
[Test] Added Map key matcher; enforced strong typing on matchers (#6561)
* Added `toHaveKey` matcher + fixed imports

* Broke up the test matchers into multiple smaller interfaces

* Added restricted typing on matchers

Now we can't call `expect(game).toHaveFullHp()`!!!!!

* Updated comment

* Renamed `toEqualArrayUnsorted` into `toEqualUnsorted`

* Moved comment at top of file

* Fix `@module` doc comment

* Remove extra space

* Fix typo

* Fixed key ssue in matchers

* Update to-have-key.ts

* Update test/@types/vitest.d.ts

Co-authored-by: NightKev <34855794+DayKev@users.noreply.github.com>

* Fixed missing braces inside comment

---------

Co-authored-by: NightKev <34855794+DayKev@users.noreply.github.com>
2025-09-20 17:24:27 -05:00

57 lines
2.0 KiB
TypeScript

import type { ModifierTypeKeys } from "#modifiers/modifier-type";
import { itemPoolChecks } from "#modifiers/modifier-type";
import { GameManagerHelper } from "#test/test-utils/helpers/game-manager-helper";
import { expect } from "vitest";
export class ModifierHelper extends GameManagerHelper {
/**
* Adds a Modifier to the list of modifiers to check for.
*
* Note that all modifiers are updated during the start of `SelectModifierPhase`.
* @param modifier The Modifier to add.
* @returns `this`
*/
addCheck(modifier: ModifierTypeKeys): this {
itemPoolChecks.set(modifier, undefined);
return this;
}
/**
* `get`s a value from the `itemPoolChecks` map.
*
* If the item is in the Modifier Pool, and the player can get it, will return `true`.
*
* If the item is *not* in the Modifier Pool, will return `false`.
*
* If a `SelectModifierPhase` has not occurred, and we do not know if the item is in the Modifier Pool or not, will return `undefined`.
* @param modifier
* @returns
*/
getCheck(modifier: ModifierTypeKeys): boolean | undefined {
return itemPoolChecks.get(modifier);
}
/**
* `expect`s a Modifier `toBeTruthy` (in the Modifier Pool) or `Falsy` (unobtainable on this floor). Use during a test.
*
* Note that if a `SelectModifierPhase` has not been run yet, these values will be `undefined`, and the check will fail.
* @param modifier The modifier to check.
* @param expectToBePreset Whether the Modifier should be in the Modifier Pool. Set to `false` to expect it to be absent instead.
* @returns `this`
*/
testCheck(modifier: ModifierTypeKeys, expectToBePreset: boolean): this {
(expectToBePreset ? expect(itemPoolChecks) : expect(itemPoolChecks).not).toHaveKey(modifier);
return this;
}
/** Removes all modifier checks. @returns `this` */
clearChecks() {
itemPoolChecks.clear();
return this;
}
private log(...params: any[]) {
console.log("Modifiers:", ...params);
}
}