Fixed up tests

This commit is contained in:
Bertie690 2025-06-07 12:21:16 -04:00
parent b996624b03
commit 8a9ff2818b
2 changed files with 11 additions and 9 deletions

View File

@ -175,11 +175,12 @@ export default class Battle {
} }
addPostBattleLoot(enemyPokemon: EnemyPokemon): void { addPostBattleLoot(enemyPokemon: EnemyPokemon): void {
this.postBattleLoot.concat( // Push used instead of concat to avoid extra allocation
globalScene.findModifiers( this.postBattleLoot.push(
...(globalScene.findModifiers(
m => m instanceof PokemonHeldItemModifier && m.pokemonId === enemyPokemon.id && m.isTransferable, m => m instanceof PokemonHeldItemModifier && m.pokemonId === enemyPokemon.id && m.isTransferable,
false, false,
) as PokemonHeldItemModifier[], ) as PokemonHeldItemModifier[]),
); );
} }

View File

@ -11,6 +11,7 @@ import GameManager from "#test/testUtils/gameManager";
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, vi } from "vitest";
import { BattlerIndex } from "#app/battle"; import { BattlerIndex } from "#app/battle";
import { StealHeldItemChanceAttr } from "#app/data/moves/move";
describe("Field - Pokemon ID Checks", () => { describe("Field - Pokemon ID Checks", () => {
let phaserGame: Phaser.Game; let phaserGame: Phaser.Game;
@ -57,7 +58,8 @@ describe("Field - Pokemon ID Checks", () => {
it("should not prevent item theft with PID of 0", async () => { it("should not prevent item theft with PID of 0", async () => {
game.override.enemyHeldItems([{ name: "BERRY", count: 1, type: BerryType.APICOT }]); game.override.enemyHeldItems([{ name: "BERRY", count: 1, type: BerryType.APICOT }]);
vi.spyOn(allMoves[MoveId.THIEF], "chance", "get").mockReturnValue(100); // Mock thief's steal chance to be 100% guaranteed
vi.spyOn(allMoves[MoveId.THIEF], "attrs", "get").mockReturnValue([new StealHeldItemChanceAttr(1.0)]);
await game.classicMode.startBattle([SpeciesId.TREECKO]); await game.classicMode.startBattle([SpeciesId.TREECKO]);
@ -72,7 +74,6 @@ describe("Field - Pokemon ID Checks", () => {
expect(enemy.getHeldItems()).toHaveLength(1); expect(enemy.getHeldItems()).toHaveLength(1);
expect(player.getHeldItems()).toHaveLength(0); expect(player.getHeldItems()).toHaveLength(0);
// Player uses Thief and steals the opponent's item
game.move.use(MoveId.THIEF); game.move.use(MoveId.THIEF);
await game.toNextTurn(); await game.toNextTurn();
@ -84,12 +85,14 @@ describe("Field - Pokemon ID Checks", () => {
await game.classicMode.startBattle([SpeciesId.TREECKO, SpeciesId.AERODACTYL]); await game.classicMode.startBattle([SpeciesId.TREECKO, SpeciesId.AERODACTYL]);
const player = game.field.getPlayerPokemon(); const player = game.field.getPlayerPokemon();
const enemy = game.field.getEnemyPokemon();
// Override player pokemon PID to be 0 // Override player pokemon PID to be 0
player.id = 0; player.id = 0;
expect(player.getTag(BattlerTagType.DESTINY_BOND)).toBeUndefined(); expect(player.getTag(BattlerTagType.DESTINY_BOND)).toBeUndefined();
game.move.use(MoveId.DESTINY_BOND); game.move.use(MoveId.DESTINY_BOND);
await game.move.forceEnemyMove(MoveId.FLARE_BLITZ); game.doSelectPartyPokemon(1);
await game.move.forceEnemyMove(MoveId.FLAME_WHEEL);
await game.setTurnOrder([BattlerIndex.PLAYER, BattlerIndex.ENEMY]); await game.setTurnOrder([BattlerIndex.PLAYER, BattlerIndex.ENEMY]);
await game.phaseInterceptor.to("MoveEndPhase"); await game.phaseInterceptor.to("MoveEndPhase");
@ -99,9 +102,7 @@ describe("Field - Pokemon ID Checks", () => {
await game.phaseInterceptor.to("MoveEndPhase"); await game.phaseInterceptor.to("MoveEndPhase");
const enemy = game.scene.getEnemyPokemon();
expect(player.isFainted()).toBe(true); expect(player.isFainted()).toBe(true);
expect(enemy).toBeUndefined(); expect(enemy.isFainted()).toBe(true);
expect(player.getTag(BattlerTagType.DESTINY_BOND)).toBeUndefined();
}); });
}); });