A Jest preset and mock library for testing scripts that use the @minecraft/server
API. This package provides typed mocks for a small portion of the Bedrock server module so you can write unit tests without needing a running game.
npm install --save-dev @bedrock-oss/minecraft-server-jest
Add the preset to your Jest configuration. This automatically registers the mocks for @minecraft/server
.
// jest.config.js
module.exports = {
preset: '@bedrock-oss/minecraft-server-jest',
};
Run Jest as normal:
npx jest
Phase checks emulate Bedrock's execution phases. They are enabled by default. Set MC_PHASE_CHECKS=false
to disable them for an entire run.
import { world } from '@minecraft/server';
test('hello world', () => {
system.run(() => {
world.sendMessage('hello');
});
});