| name | unit-test |
| description | Create and run Jest unit tests. Use when implementing tests or validating changes. |
Unit Testing in Pokestar
Quick Reference
Test location: src/<module>/__tests__/<name>.test.js
Run all tests:
npm test
Run specific test file:
npm test -- src/battle/data/__tests__/moves.test.js
Run tests matching a pattern:
npm test -- --testNamePattern="move.*execute"
Test Setup
Tests use the setup file at src/__testing__/setup.js which:
- Mocks the database via
src/__testing__/mocks/database.js
- Initializes battle data via
initialize()
If new setup should be added for all tests, add them in this file.
Available Mocks
Mocks for tests are located in src/__testing__/mocks. Use these utilites to create mock data for testing. If new mocks are needed, create those mocks in this directory.
Available Utilities
Test utilities are located in src/__testing__/utils. Use these utilities when invoking commonly-reused testing functionality. If a new common test pattern should be utilized, create new utils for it here.
Test Structure
const { createMockBattle } = require("../../../__testing__/mocks/battle");
const {
getValidTargetForMove,
givePokemonMove,
} = require("../../../__testing__/utils/battle");
describe("Feature Name", () => {
it("should do something", () => {
const { battle } = createMockBattle({ autoStart: true });
const { activePokemon } = battle;
expect(result).toBe(expected);
});
});
Relevant Skills
For additional instructions, refer to the following skills on how to create tests:
test-move: Create tests for Pokemon Battle moves
Running After Implementation
After implementing a feature that has tests, run the relevant test suite:
npm test -- <path-to-test-file>
If tests fail:
- Read the error message to understand what failed
- Fix the implementation (not the test, unless the test is wrong)
- Re-run the tests
- Repeat until all tests pass