-
Notifications
You must be signed in to change notification settings - Fork 3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added new common.js tests (expresso-like), with browser-compliant sho…
…uld().
- Loading branch information
Showing
4 changed files
with
638 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
|
||
/*! | ||
* socket.io-node | ||
* Copyright(c) 2011 LearnBoost <dev@learnboost.com> | ||
* MIT Licensed | ||
*/ | ||
|
||
(function (module, io, should) { | ||
|
||
module.exports = { | ||
|
||
'add listeners': function () { | ||
var event = new io.EventEmitter | ||
, calls = 0; | ||
|
||
event.on('test', function (a, b) { | ||
++calls; | ||
a.should().eql('a'); | ||
b.should().eql('b'); | ||
}); | ||
|
||
event.emit('test', 'a', 'b'); | ||
calls.should().eql(1); | ||
event.on.should().eql(event.addListener); | ||
}, | ||
|
||
'remove listener': function () { | ||
var event = new io.EventEmitter; | ||
function empty () { } | ||
|
||
event.on('test', empty); | ||
event.on('test:more', empty); | ||
event.removeAllListeners('test'); | ||
|
||
event.listeners('test').should().eql([]); | ||
event.listeners('test:more').should().eql([empty]); | ||
}, | ||
|
||
'remove all listeners': function () { | ||
var event = new io.EventEmitter; | ||
function empty () { } | ||
|
||
event.on('test', empty); | ||
event.on('test:more', empty); | ||
event.removeAllListeners(); | ||
|
||
event.listeners('test').should().eql([empty]); | ||
event.listeners('test:more').should().eql([empty]); | ||
}, | ||
|
||
'remove listeners functions': function () { | ||
var event = new io.EventEmitter | ||
, calls = 0; | ||
|
||
function one () { ++calls } | ||
function two () { ++calls } | ||
function three () { ++calls } | ||
|
||
event.on('one', one); | ||
event.removeListener('one', one); | ||
event.listeners('one').should().eql([]); | ||
|
||
event.on('two', two); | ||
event.removeListener('two', one); | ||
event.listeners('two').should().eql([two]); | ||
|
||
event.on('three', three); | ||
event.on('three', two); | ||
event.removeListener('three', three); | ||
event.listeners('three').should().eql([two]); | ||
}, | ||
|
||
'number of arguments': function () { | ||
var event = new io.EventEmitter | ||
, number = []; | ||
|
||
event.on('test', function () { | ||
number.push(arguments.length); | ||
}); | ||
|
||
event.emit('test'); | ||
event.emit('test', null); | ||
event.emit('test', null, null); | ||
event.emit('test', null, null, null); | ||
event.emit('test', null, null, null, null); | ||
event.emit('test', null, null, null, null, null); | ||
|
||
[0, 1, 2, 3, 4, 5].should().eql(number); | ||
}, | ||
|
||
'once': function () { | ||
var event = new io.EventEmitter | ||
, calls = 0; | ||
|
||
event.once('test', function (a, b) { | ||
++calls; | ||
}); | ||
|
||
event.emit('test', 'a', 'b'); | ||
event.emit('test', 'a', 'b'); | ||
event.emit('test', 'a', 'b'); | ||
|
||
function removed () { | ||
should().fail('not removed'); | ||
}; | ||
|
||
event.once('test:removed', removed); | ||
event.removeListener('test:removed', removed); | ||
event.emit('test:removed'); | ||
|
||
calls.should().eql(1); | ||
} | ||
|
||
}; | ||
|
||
})( | ||
'undefined' == typeof module ? module = {} : module | ||
, 'undefined' == typeof io ? require('socket.io-client') : io | ||
, 'undefined' == typeof should || !should.fail ? require('should') : should | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
|
||
/*! | ||
* socket.io-node | ||
* Copyright(c) 2011 LearnBoost <dev@learnboost.com> | ||
* MIT Licensed | ||
*/ | ||
|
||
(function (module, io, should) { | ||
|
||
module.exports = { | ||
|
||
'client version number': function () { | ||
io.version.should().match(/([0-9]+)\.([0-9]+)\.([0-9]+)/); | ||
}, | ||
|
||
'socket.io protocol version': function () { | ||
io.protocol.should().be.a('number'); | ||
io.protocol.toString().should().match(/^\d+$/); | ||
}, | ||
|
||
'socket.io available transports': function () { | ||
(io.transports.length > 0).should().be_true; | ||
} | ||
|
||
}; | ||
|
||
})( | ||
'undefined' == typeof module ? module = {} : module | ||
, 'undefined' == typeof io ? require('socket.io-client') : io | ||
, 'undefined' == typeof should ? require('should') : should | ||
); |
Oops, something went wrong.