Fix mock RNG function used by tests

Also remove unnecessary extra RNG mock from Glaive Rush test
This commit is contained in:
NightKev 2024-08-20 05:53:51 -07:00
parent 1fb6656c22
commit 360ae8cff9
2 changed files with 10 additions and 12 deletions

View File

@ -1,13 +1,13 @@
import { allMoves } from "#app/data/move.js"; import { allMoves } from "#app/data/move";
import { Abilities } from "#app/enums/abilities.js"; import { Abilities } from "#app/enums/abilities";
import GameManager from "#test/utils/gameManager"; import { DamagePhase } from "#app/phases/damage-phase";
import { getMovePosition } from "#test/utils/gameManagerUtils"; import { TurnEndPhase } from "#app/phases/turn-end-phase";
import { Moves } from "#enums/moves"; import { Moves } from "#enums/moves";
import { Species } from "#enums/species"; import { Species } from "#enums/species";
import GameManager from "#test/utils/gameManager";
import { getMovePosition } from "#test/utils/gameManagerUtils";
import Phaser from "phaser"; import Phaser from "phaser";
import { afterEach, beforeAll, beforeEach, describe, expect, it, vi } from "vitest"; import { afterEach, beforeAll, beforeEach, describe, expect, it } from "vitest";
import { DamagePhase } from "#app/phases/damage-phase.js";
import { TurnEndPhase } from "#app/phases/turn-end-phase.js";
describe("Moves - Glaive Rush", () => { describe("Moves - Glaive Rush", () => {
@ -32,8 +32,7 @@ describe("Moves - Glaive Rush", () => {
game.override.enemyAbility(Abilities.BALL_FETCH); game.override.enemyAbility(Abilities.BALL_FETCH);
game.override.enemyMoveset(Array(4).fill(Moves.GLAIVE_RUSH)); game.override.enemyMoveset(Array(4).fill(Moves.GLAIVE_RUSH));
game.override.starterSpecies(Species.KLINK); game.override.starterSpecies(Species.KLINK);
game.override.ability(Abilities.UNNERVE); game.override.ability(Abilities.BALL_FETCH);
game.override.passiveAbility(Abilities.FUR_COAT);
game.override.moveset([Moves.SHADOW_SNEAK, Moves.AVALANCHE, Moves.SPLASH, Moves.GLAIVE_RUSH]); 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()!; const enemy = game.scene.getEnemyPokemon()!;
enemy.hp = 1000; enemy.hp = 1000;
vi.spyOn(game.scene, "randBattleSeedInt").mockReturnValue(0);
game.doAttack(getMovePosition(game.scene, 0, Moves.SHADOW_SNEAK)); game.doAttack(getMovePosition(game.scene, 0, Moves.SHADOW_SNEAK));
await game.phaseInterceptor.to(DamagePhase); await game.phaseInterceptor.to(DamagePhase);
const damageDealt = 1000 - enemy.hp; const damageDealt = 1000 - enemy.hp;
@ -51,7 +49,7 @@ describe("Moves - Glaive Rush", () => {
await game.phaseInterceptor.to(DamagePhase); await game.phaseInterceptor.to(DamagePhase);
expect(enemy.hp).toBeLessThanOrEqual(1001 - (damageDealt * 3)); expect(enemy.hp).toBeLessThanOrEqual(1001 - (damageDealt * 3));
}, 5000); // TODO: revert back to 20s }, 20000);
it("always gets hit by attacks", async() => { it("always gets hit by attacks", async() => {
await game.startBattle(); await game.startBattle();

View File

@ -66,7 +66,7 @@ export default class GameManager {
constructor(phaserGame: Phaser.Game, bypassLogin: boolean = true) { constructor(phaserGame: Phaser.Game, bypassLogin: boolean = true) {
localStorage.clear(); localStorage.clear();
ErrorInterceptor.getInstance().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.gameWrapper = new GameWrapper(phaserGame, bypassLogin);
this.scene = new BattleScene(); this.scene = new BattleScene();
this.phaseInterceptor = new PhaseInterceptor(this.scene); this.phaseInterceptor = new PhaseInterceptor(this.scene);