File size: 1,245 Bytes
5fae594 |
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 |
'use strict';
var should = require('should');
var Broadcast = require('../../source/broadcast');
var Room = {
last: {},
get: function (name) {
return {
id: name,
broadcast: function (sender, event, a1, a2, a3) {
Room.last[name] = [sender, event, a1, a2, a3];
}
};
}
};
describe('Broadcast', function () {
before(function () {
Broadcast.init(Room);
});
describe('.bind', function () {
it('should bind to obj', function () {
var obj = {};
var broadcast = Broadcast.bind(obj);
broadcast.should.have.type('function');
broadcast.to.should.have.type('function');
});
});
describe(':broadcast', function () {
it('should remember itself', function () {
var obj = { id: 'self' };
var broadcast = Broadcast.bind(obj);
broadcast('event', 1, 2, 3);
Room.last.all.should.eql([ 'self', 'event', 1, 2, 3 ]);
});
});
describe(':broadcastTo', function () {
it('should broadcast to a room', function () {
var obj = { id: 'self' };
var broadcast = Broadcast.bind(obj);
broadcast.to('my_room').emit('event', 1, 2, 3);
Room.last.my_room.should.eql([ 'self', 'event', 1, 2, 3 ]);
});
});
});
|