|
2 | 2 | 'use strict'; |
3 | 3 |
|
4 | 4 | describe('Angular Socket.io Mock',function(){ |
| 5 | + var socketFactory; |
5 | 6 | beforeEach(module('btford.socket-io')) |
6 | | - it('should be able to listen on an event',inject(function(socketFactory){ |
| 7 | + beforeEach(inject(function(_socketFactory_){ socketFactory = _socketFactory_ })); |
| 8 | + it('should be able to listen on an event', function(){ |
7 | 9 | expect(new socketFactory().on('test-event',function(){})).not.toBe(false) |
8 | | - })) |
9 | | - it('should be able to listen once event',inject(function(socketFactory){ |
10 | | - expect(socketFactory.once('test-event',function(){})).not.toBe(false) |
11 | | - })) |
12 | | - it('should be able to emit an event',inject(function(socketFactory){ |
| 10 | + }); |
| 11 | + it('should be able to listen once event', function(){ |
| 12 | + expect(new socketFactory().once('test-event',function(){})).not.toBe(false) |
| 13 | + }); |
| 14 | + it('should be able to emit an event', function(){ |
13 | 15 | expect(new socketFactory().emit('test-event',{})).not.toBe(false) |
14 | | - })) |
15 | | - it('should be able to receive an event',inject(function(socketFactory){ |
| 16 | + }); |
| 17 | + it('should be able to receive an event', function(){ |
16 | 18 | expect(new socketFactory().receive('test-event',{})).not.toBe(false) |
17 | | - })) |
| 19 | + }); |
| 20 | + it('should be able to acknowledge an emited event only once',function(done){ |
| 21 | + var socket = new socketFactory(); |
| 22 | + var timesCalled = 0; |
| 23 | + |
| 24 | + socket.emit('test-event',{}, function(resp){ |
| 25 | + expect(resp).not.toBe(false); |
| 26 | + expect(++timesCalled).toEqual(1); |
| 27 | + }); |
| 28 | + |
| 29 | + socket.receive('test-event', {}); |
| 30 | + socket.receive('test-event', {}); |
| 31 | + |
| 32 | + setTimeout(function() { // Wait to see if the event was acknowledged twice |
| 33 | + done(); |
| 34 | + }, 100); |
| 35 | + }); |
18 | 36 | }) |
0 commit comments