diff --git a/src/ai/ai-moveset-gen.ts b/src/ai/ai-moveset-gen.ts index 043c93451cf..f392ca46d3f 100644 --- a/src/ai/ai-moveset-gen.ts +++ b/src/ai/ai-moveset-gen.ts @@ -133,6 +133,8 @@ function getTmPoolForSpecies( ): void { const [allowCommon, allowGreat, allowUltra] = allowedTiers; const tms = speciesTmMoves[speciesId]; + // Species with no learnable TMs (e.g. Ditto) don't have entries in the `speciesTmMoves` object, + // so this is needed to avoid iterating over `undefined` if (tms == null) { return; } diff --git a/test/ai/ai-moveset-gen.test.ts b/test/ai/ai-moveset-gen.test.ts index 86ca929be77..6d927926131 100644 --- a/test/ai/ai-moveset-gen.test.ts +++ b/test/ai/ai-moveset-gen.test.ts @@ -41,6 +41,8 @@ interface MockPokemonParams { /** * Construct an `EnemyPokemon` that can be used for testing * @param species - The species ID of the pokemon to create + * @returns The newly created `EnemyPokemon`. + * @todo Move this to a dedicated unit test util folder if more tests come to rely on it */ function createTestablePokemon( species: SpeciesId, @@ -269,7 +271,7 @@ describe("Regression Tests - ai-moveset-gen.ts", () => { describe("getTmPoolForSpecies", () => { const { getTmPoolForSpecies } = __INTERNAL_TEST_EXPORTS; - it("should not crash when generating a moveset for Ditto", () => { + it("should not crash when generating a moveset for Pokemon without TM moves", () => { pokemon = createTestablePokemon(SpeciesId.DITTO, { level: 50 }); expect(() => getTmPoolForSpecies(SpeciesId.DITTO, ULTRA_TIER_TM_LEVEL_REQUIREMENT, "", new Map(), new Map(), new Map(), [