nav tabs on admin dashboard
This commit is contained in:
+44
-20
@@ -19,41 +19,65 @@
|
||||
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
|
||||
// USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
|
||||
var common = require('./common');
|
||||
var assert = require('assert');
|
||||
var events = require('../');
|
||||
var EventEmitter = require('../');
|
||||
|
||||
var e = new events.EventEmitter();
|
||||
var times_hello_emited = 0;
|
||||
var e = new EventEmitter();
|
||||
|
||||
e.once('hello', function(a, b) {
|
||||
times_hello_emited++;
|
||||
});
|
||||
e.once('hello', common.mustCall());
|
||||
|
||||
e.emit('hello', 'a', 'b');
|
||||
e.emit('hello', 'a', 'b');
|
||||
e.emit('hello', 'a', 'b');
|
||||
e.emit('hello', 'a', 'b');
|
||||
|
||||
var remove = function() {
|
||||
assert.fail(1, 0, 'once->foo should not be emitted', '!');
|
||||
};
|
||||
function remove() {
|
||||
assert.fail('once->foo should not be emitted');
|
||||
}
|
||||
|
||||
e.once('foo', remove);
|
||||
e.removeListener('foo', remove);
|
||||
e.emit('foo');
|
||||
|
||||
var times_recurse_emitted = 0;
|
||||
e.once('e', common.mustCall(function() {
|
||||
e.emit('e');
|
||||
}));
|
||||
|
||||
e.once('e', function() {
|
||||
e.emit('e');
|
||||
times_recurse_emitted++;
|
||||
});
|
||||
|
||||
e.once('e', function() {
|
||||
times_recurse_emitted++;
|
||||
});
|
||||
e.once('e', common.mustCall());
|
||||
|
||||
e.emit('e');
|
||||
|
||||
assert.equal(1, times_hello_emited);
|
||||
assert.equal(2, times_recurse_emitted);
|
||||
// Verify that the listener must be a function
|
||||
assert.throws(function() {
|
||||
var ee = new EventEmitter();
|
||||
|
||||
ee.once('foo', null);
|
||||
}, /^TypeError: The "listener" argument must be of type Function. Received type object$/);
|
||||
|
||||
{
|
||||
// once() has different code paths based on the number of arguments being
|
||||
// emitted. Verify that all of the cases are covered.
|
||||
var maxArgs = 4;
|
||||
|
||||
for (var i = 0; i <= maxArgs; ++i) {
|
||||
var ee = new EventEmitter();
|
||||
var args = ['foo'];
|
||||
|
||||
for (var j = 0; j < i; ++j)
|
||||
args.push(j);
|
||||
|
||||
ee.once('foo', common.mustCall(function() {
|
||||
var params = Array.prototype.slice.call(arguments);
|
||||
var restArgs = args.slice(1);
|
||||
assert.ok(Array.isArray(params));
|
||||
assert.strictEqual(params.length, restArgs.length);
|
||||
for (var index = 0; index < params.length; index++) {
|
||||
var param = params[index];
|
||||
assert.strictEqual(param, restArgs[index]);
|
||||
}
|
||||
}));
|
||||
|
||||
EventEmitter.prototype.emit.apply(ee, args);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user