-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
2 changed files
with
107 additions
and
80 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
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 |
---|---|---|
@@ -1,51 +1,81 @@ | ||
var Ant = require('../lib/ant'); | ||
var dnode = require('dnode'), | ||
Ant = require('../lib/ant'), | ||
EventEmitter = require('eventemitter2').EventEmitter2; | ||
|
||
describe('Ant', function() { | ||
|
||
var ant = null; | ||
|
||
beforeEach(function() { | ||
ant = new Ant(); | ||
ant.start(); | ||
describe('constructor', function() { | ||
it( 'should be instance of EventEmitter', function() { | ||
expect( new Ant() instanceof EventEmitter ).toBeTruthy(); | ||
}) | ||
|
||
it( 'should pass name', function() { | ||
expect( new Ant({name: 'foo'}).name ).toEqual('foo'); | ||
}) | ||
|
||
it( 'should pass port', function() { | ||
expect( new Ant({port: 9000}).port ).toEqual(9000); | ||
}) | ||
|
||
it( 'should pass debug', function() { | ||
expect( new Ant({debug: true}).debug ).toEqual(true); | ||
}) | ||
|
||
it( 'should have debug disabled by default', function() { | ||
expect( new Ant().debug ).toEqual(false); | ||
}) | ||
}) | ||
|
||
afterEach(function() { | ||
try { | ||
ant.stop(); | ||
} catch(err) {} | ||
}) | ||
describe( '', function() { | ||
var ant = null; | ||
|
||
it('server should be defined', function() { | ||
expect(ant.server.server).toBeDefined(); | ||
}) | ||
beforeEach(function() { | ||
ant = new Ant(); | ||
ant.start(); | ||
}) | ||
|
||
describe('.emit', function() { | ||
it('server emit an event', function() { | ||
var s = spyOn(ant.emitter, 'emit') | ||
ant.emit('foo', {bar: 'baz'}); | ||
|
||
expect(s).toHaveBeenCalledWith('foo', { | ||
name : 'foo', | ||
data : { bar : 'baz' } | ||
}); | ||
afterEach(function() { | ||
try { | ||
ant.stop(); | ||
} catch(err) {} | ||
}) | ||
}) | ||
|
||
describe('.on', function() { | ||
it('should call proper client on method', function() { | ||
client = { | ||
on: function() {} | ||
} | ||
it('server should be defined', function() { | ||
expect(ant.server.server).toBeDefined(); | ||
}) | ||
|
||
describe('.emit', function() { | ||
it('server emit an event', function() { | ||
var s = spyOn(EventEmitter.prototype, 'emit') | ||
ant.emit('foo', {bar: 'baz'}); | ||
|
||
ant._connections['ant-name'] = { | ||
client: client | ||
} | ||
expect(s).toHaveBeenCalledWith('foo', { | ||
name : 'foo', | ||
data : { bar : 'baz' } | ||
}); | ||
}) | ||
}) | ||
|
||
describe('.connect', function() { | ||
it('should connect to dnode server', function() { | ||
var s = spyOn( dnode, 'connect' ) | ||
ant.connect( 1000, function() {} ) | ||
expect(s).toHaveBeenCalled(); | ||
}) | ||
|
||
var s = spyOn(client, 'on') | ||
it('should connect to dnode server with given port', function() { | ||
var s = spyOn( dnode, 'connect' ) | ||
ant.connect( '4000', function() {} ) | ||
expect(s).toHaveBeenCalledWith('4000', jasmine.any(Function)); | ||
}) | ||
|
||
var f = function() {} | ||
ant.on('ant-name', 'foo', f); | ||
expect(s).toHaveBeenCalledWith('foo', f) | ||
it('should connect to dnode server with given host and port', function() { | ||
var params = { host: '192.168.0.1', port: 3000 }, | ||
s = spyOn( dnode, 'connect' ); | ||
|
||
ant.connect( params, function() {} ) | ||
expect(s).toHaveBeenCalledWith( params, jasmine.any(Function) ); | ||
}) | ||
}) | ||
}) | ||
}) |