it('when another client connect server should emit correct "presence"', function(done) { newSocket = socketClient(config.SELF_URL); newSocket.on('presence', function(presence) { expect(presence).to.be.an('object'); expect(presence).to.have.property('numUsers'); expect(presence.numUsers).to.equal(1); newSocket.off('presence'); done(); }); });
describe('The application server', function() { it('should serve webpages over HTTP', async function() { var result = await client.get('index.html'); expect(result.statusCode).to.equal(200); }); it('should have a socket.io server', async function() { var socket = socketClient(config.SELF_URL); await new Promise(function(resolve) { socket.on('connect', resolve); }); socket.disconnect(); }); });
it('should accept a connection and emit "presence" to it', function(done) { var callbacks = 2; socket = socketClient(config.SELF_URL); var end = function() { socket.off('presence'); done(); }; socket.on('connect', function() { --callbacks > 0 || end(); }); socket.on('presence', function(presence) { expect(presence).to.be.an('object'); expect(presence).to.have.property('numUsers'); expect(presence.numUsers).to.equal(0); --callbacks > 0 || end(); }); });