Environment and helper functions for unit testing your Screeps bot with Jest.
Features:
RoomPosition
already mockedyarn add screeps-jest --dev
or
npm install screeps-jest --save-dev
// jest.config.js
module.exports = {
// ...
testEnvironment: "screeps-jest"
// ...
};
// *.spec.ts
import { mockGlobal, mockInstanceOf, mockStructure } from "screeps-jest";
mockGlobal<Game>('Game', {
time: 123
});
const creep = mockInstanceOf<Creep>({
moveTo: () => OK,
store: {
getFreeCapacity: () => 0
},
transfer: () => ERR_NOT_IN_RANGE
});
const spawn = mockStructure(STRUCTURE_SPAWN, {
hits: 5000,
hitsMax: 5000
});
Check screeps-typescript-jest-starter for a more complete example of how to use screeps-jest to unit test a Screeps bot in TypeScript.
If you find a bug or have a feature request, please create an issue. If you have trouble using screeps-jest
, ask on #typescript channel on Screeps' Discord server. I hang out there often, and someone else there might be able to help you also.