Skip to content

Commit

Permalink
started tests
Browse files Browse the repository at this point in the history
  • Loading branch information
tj committed Apr 26, 2012
1 parent 995087e commit a9ef80d
Show file tree
Hide file tree
Showing 3 changed files with 96 additions and 1 deletion.
6 changes: 5 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,8 @@ stats:
@du -hs build/* | sed 's/^/ /'
@echo

.PHONY: ui stats
test:
@./node_modules/.bin/mocha \
--require should

.PHONY: ui stats test
11 changes: 11 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"author": "TJ Holowaychuk <[email protected]>",
"name": "uikit",
"description": "UIKit",
"version": "0.0.1",
"dependencies": {},
"devDependencies": {
"mocha": "*",
"should": "*"
}
}
80 changes: 80 additions & 0 deletions test/emitter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@

var Emitter = require('../lib/components/emitter/emitter').Emitter;

describe('Emitter', function(){
describe('.on(event, fn)', function(){
it('should add listeners', function(){
var emitter = new Emitter;
var calls = [];

emitter.on('foo', function(val){
calls.push('one', val);
});

emitter.on('foo', function(val){
calls.push('two', val);
});

emitter.emit('foo', 1);
emitter.emit('bar', 1);
emitter.emit('foo', 2);

calls.should.eql([ 'one', 1, 'two', 1, 'one', 2, 'two', 2 ]);
})
})

describe('.once(event, fn)', function(){
it('should add a single-shot listener', function(){
var emitter = new Emitter;
var calls = [];

emitter.once('foo', function(val){
calls.push('one', val);
});

emitter.emit('foo', 1);
emitter.emit('foo', 2);
emitter.emit('foo', 3);
emitter.emit('bar', 1);

calls.should.eql([ 'one', 1 ]);
})
})

describe('.off(event, fn)', function(){
it('should remove a listener', function(){
var emitter = new Emitter;
var calls = [];

function one() { calls.push('one'); }
function two() { calls.push('two'); }

emitter.on('foo', one);
emitter.on('foo', two);
emitter.off('foo', two);

emitter.emit('foo');

calls.should.eql([ 'one' ]);
})
})

describe('.off(event)', function(){
it('should remove all listeners for an event', function(){
var emitter = new Emitter;
var calls = [];

function one() { calls.push('one'); }
function two() { calls.push('two'); }

emitter.on('foo', one);
emitter.on('foo', two);
emitter.off('foo');

emitter.emit('foo');
emitter.emit('foo');

calls.should.eql([]);
})
})
})

0 comments on commit a9ef80d

Please sign in to comment.