Spaces:
Running
Running
File size: 1,952 Bytes
5c2ed06 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
'use strict';
const assert = require('./../assert');
const common = require('./../common');
let battle;
describe('Battle#on', () => {
afterEach(() => {
battle.destroy();
});
it('should allow the addition of one or more event handlers to the battle engine', () => {
battle = common.createBattle([
[{ species: 'Pidgeot', ability: 'keeneye', moves: ['bulkup'] }],
[{ species: 'Talonflame', ability: 'galewings', moves: ['peck'] }],
]);
let eventCount = 0;
let eventCount2 = 0;
battle.onEvent('Hit', battle.format, () => {
eventCount++;
});
battle.onEvent('Hit', battle.format, () => {
eventCount++;
eventCount2++;
});
battle.onEvent('ModifyDamage', battle.format, () => {
return 5;
});
battle.makeChoices('move bulkup', 'move peck');
assert.equal(eventCount, 4);
assert.equal(eventCount2, 2);
assert.equal(battle.p1.active[0].maxhp - battle.p1.active[0].hp, 5);
});
it('should support and resolve priorities correctly', () => {
battle = common.createBattle([
[{ species: 'Pidgeot', ability: 'keeneye', moves: ['bulkup'] }],
[{ species: 'Talonflame', ability: 'galewings', moves: ['peck'] }],
]);
let eventCount = 0;
const modHandler = function (count) {
return function () {
assert.equal(eventCount, count);
eventCount++;
};
};
for (let i = 0; i < 9; i++) {
battle.onEvent('ModifyDamage', battle.format, -i, modHandler(i));
}
battle.makeChoices('move bulkup', 'move peck');
assert.equal(eventCount, 9);
});
it('should throw if a callback is not given for the event handler', () => {
battle = common.createBattle([
[{ species: 'Pidgeot', ability: 'keeneye', moves: ['bulkup'] }],
[{ species: 'Talonflame', ability: 'galewings', moves: ['peck'] }],
]);
assert.throws(battle.onEvent, TypeError);
assert.throws(() => { battle.onEvent('Hit'); }, TypeError);
assert.throws(() => { battle.onEvent('Hit', battle.format); }, TypeError);
});
});
|