I have a test that checks if the joined event is emitted correctly when a users subscribe to a room. However, I want to write a test to make sure when chatUser2 joins room2 that the joined event is only received by her and not client1 in room1
How would I write a test to make sure client1.on('joined') is NOT called when client2 connects?
var should = require('should'),
io = require('socket.io-client'),
path = require('path'),
express = require(path.resolve('./config/lib/express')),
mongoose = require('mongoose'),
sinon = require('sinon'),
app, agent, credentials, user, sale;
var chatUser1 = {'name':'Tom', 'room':'room1'};
var chatUser2 = {'name':'Sally', 'room':'room2'};
describe("Socket Server",function(){
it('Should not broadcast joined event to unsubscribed rooms', function(done){
var client1 = io.connect(socketURL, options);
client1.on('connect', function(data){
client1.emit('subscribe', chatUser1);
client1.on('joined', function(data){
data.should.equal(chatUser1.name + " has joined "+chatUser1.room);
});
var client2 = io.connect(socketURL, options);
client2.on('connect', function(data){
client2.emit('subscribe', chatUser2);
});
client2.on('joined', function(data){
data.should.equal(chatUser2.name + " has joined "+chatUser2.room);
client1.disconnect();
client2.disconnect();
done();
});
});
});
});
Aucun commentaire:
Enregistrer un commentaire