pokemon-showdown/test/application/rooms.js
Guangcong Luo b665660608 Refactor for more ES6 features
Now that nodejs/node#3072 is mostly fixed, we can finally start using
Node 4+ features.

This refactor:

- uses arrow functions where appropriate

  Note that arrow functions still aren't used in Mocha, where `this`
  is sometimes meaningful.

  This also removes the need for .bind() nearly everywhere, as well
  as the `self = this` trick.

- refactors Validator and Connection into ES6 classes

- no longer uses Array#forEach for iterating arrays

  We strongly prefer for (let i = 0; i < arr.length; i++) because of
  performance reasons. Most forEaches have been replaced with for..of,
  though, which is 5x slower than the long-form loop but 2x faster
  than forEach, which is good enough outside of most inner loops.

  The only exception is tournaments, which is due for a more invasive
  refactor soon anyway.
2016-02-10 17:40:21 -06:00

48 lines
1.5 KiB
JavaScript

'use strict';
const assert = require('assert');
let userUtils = require('./../../dev-tools/users-utils.js');
let User = userUtils.User;
describe('Rooms features', function () {
describe('Rooms', function () {
describe('Rooms.get', function () {
it('should be a function', function () {
assert.strictEqual(typeof Rooms.get, 'function');
});
it('should be equal to `Rooms`', function () {
assert.strictEqual(Rooms.get, Rooms);
});
});
describe('Rooms.rooms', function () {
it('should have null prototype', function () {
assert.strictEqual(Object.getPrototypeOf(Rooms.rooms), null);
});
it('should not have a native `constructor`', function () {
assert.ok(Rooms.rooms.constructor === undefined || Rooms.rooms.constructor instanceof Rooms.Room);
});
});
});
describe('BattleRoom', function () {
let room;
afterEach(function () {
if (room) room.expire();
});
it('should allow two users to join the battle', function () {
let p1 = new User();
let p2 = new User();
let packedTeam = 'Weavile||lifeorb||swordsdance,knockoff,iceshard,iciclecrash|Jolly|,252,,,4,252|||||';
let options = [{rated: false, tour: false}, {rated: false, tour: true}, {rated: true, tour: false}, {rated: true, tour: true}];
for (let option of options) {
room = Rooms.global.startBattle(p1, p2, 'customgame', packedTeam, packedTeam, option);
assert.ok(room.battle.p1 && room.battle.p2); // Automatically joined
}
});
});
});