From 360ae8cff9e991daa629f85ab6fbd4cd1ec1916d Mon Sep 17 00:00:00 2001 From: NightKev <34855794+DayKev@users.noreply.github.com> Date: Tue, 20 Aug 2024 05:53:51 -0700 Subject: [PATCH] Fix mock RNG function used by tests Also remove unnecessary extra RNG mock from Glaive Rush test --- src/test/moves/glaive_rush.test.ts | 20 +++++++++----------- src/test/utils/gameManager.ts | 2 +- 2 files changed, 10 insertions(+), 12 deletions(-) diff --git a/src/test/moves/glaive_rush.test.ts b/src/test/moves/glaive_rush.test.ts index f97ba1f0367..3d4d2da743d 100644 --- a/src/test/moves/glaive_rush.test.ts +++ b/src/test/moves/glaive_rush.test.ts @@ -1,13 +1,13 @@ -import { allMoves } from "#app/data/move.js"; -import { Abilities } from "#app/enums/abilities.js"; -import GameManager from "#test/utils/gameManager"; -import { getMovePosition } from "#test/utils/gameManagerUtils"; +import { allMoves } from "#app/data/move"; +import { Abilities } from "#app/enums/abilities"; +import { DamagePhase } from "#app/phases/damage-phase"; +import { TurnEndPhase } from "#app/phases/turn-end-phase"; import { Moves } from "#enums/moves"; import { Species } from "#enums/species"; +import GameManager from "#test/utils/gameManager"; +import { getMovePosition } from "#test/utils/gameManagerUtils"; import Phaser from "phaser"; -import { afterEach, beforeAll, beforeEach, describe, expect, it, vi } from "vitest"; -import { DamagePhase } from "#app/phases/damage-phase.js"; -import { TurnEndPhase } from "#app/phases/turn-end-phase.js"; +import { afterEach, beforeAll, beforeEach, describe, expect, it } from "vitest"; describe("Moves - Glaive Rush", () => { @@ -32,8 +32,7 @@ describe("Moves - Glaive Rush", () => { game.override.enemyAbility(Abilities.BALL_FETCH); game.override.enemyMoveset(Array(4).fill(Moves.GLAIVE_RUSH)); game.override.starterSpecies(Species.KLINK); - game.override.ability(Abilities.UNNERVE); - game.override.passiveAbility(Abilities.FUR_COAT); + game.override.ability(Abilities.BALL_FETCH); game.override.moveset([Moves.SHADOW_SNEAK, Moves.AVALANCHE, Moves.SPLASH, Moves.GLAIVE_RUSH]); }); @@ -42,7 +41,6 @@ describe("Moves - Glaive Rush", () => { const enemy = game.scene.getEnemyPokemon()!; enemy.hp = 1000; - vi.spyOn(game.scene, "randBattleSeedInt").mockReturnValue(0); game.doAttack(getMovePosition(game.scene, 0, Moves.SHADOW_SNEAK)); await game.phaseInterceptor.to(DamagePhase); const damageDealt = 1000 - enemy.hp; @@ -51,7 +49,7 @@ describe("Moves - Glaive Rush", () => { await game.phaseInterceptor.to(DamagePhase); expect(enemy.hp).toBeLessThanOrEqual(1001 - (damageDealt * 3)); - }, 5000); // TODO: revert back to 20s + }, 20000); it("always gets hit by attacks", async() => { await game.startBattle(); diff --git a/src/test/utils/gameManager.ts b/src/test/utils/gameManager.ts index d60cbd62836..972313bfcbc 100644 --- a/src/test/utils/gameManager.ts +++ b/src/test/utils/gameManager.ts @@ -66,7 +66,7 @@ export default class GameManager { constructor(phaserGame: Phaser.Game, bypassLogin: boolean = true) { localStorage.clear(); ErrorInterceptor.getInstance().clear(); - BattleScene.prototype.randBattleSeedInt = (arg) => arg-1; + BattleScene.prototype.randBattleSeedInt = (range, min: number = 0) => min + range - 1; // This simulates a max roll this.gameWrapper = new GameWrapper(phaserGame, bypassLogin); this.scene = new BattleScene(); this.phaseInterceptor = new PhaseInterceptor(this.scene);