girc
Version:
IRC Client library
41 lines (39 loc) • 1.6 kB
JavaScript
/*jslint node: true, vars: true*/
/*global describe, it*/
;
var Stream = require('stream').PassThrough;
var Connection = require('../lib/connection');
describe('connection.js', function () {
describe('constructor without id', function () {
it('should allocate unique id', function (done) {
var connection = new Connection({}, new Stream());
connection.getId().should.match(/^server_\d+$/);
done();
});
});
describe('getStream()', function () {
it('should return stream', function (done) {
var connection = new Connection({id: 'test_connection_1'}, new Stream());
connection.getStream().should.be.an.instanceof(Stream);
done();
});
});
describe('getId()', function () {
it('should return connection id', function (done) {
var connection = new Connection({id: 'test_connection_2'}, new Stream());
connection.getId().should.equal('test_connection_2');
done();
});
});
describe('write(str)', function () {
it('should write <str> to stream', function (done) {
var stream = new Stream();
var connection = new Connection({id: 'test_connection_3'}, stream, new (require('events').EventEmitter)());
stream.once('data', function (chunk) {
chunk.toString().should.equal('example string\r\n');
done();
});
connection.write('example string');
});
});
});