Skip to content

Commit

Permalink
Add unit tests for Todos
Browse files Browse the repository at this point in the history
  • Loading branch information
vesln committed Jan 18, 2014
1 parent cd314c6 commit 2b5947d
Show file tree
Hide file tree
Showing 3 changed files with 111 additions and 3 deletions.
6 changes: 4 additions & 2 deletions hydro.conf.js
Expand Up @@ -37,14 +37,16 @@ module.exports = function(hydro) {
formatter: 'hydro-doc',
chai: {
styles: 'should',
stack: true
stack: true,
plugins: ['jack-chai'],
},
globals: {
cli: cli,
},
plugins: [
'hydro-bdd',
'hydro-chai'
'hydro-chai',
'hydro-jack',
],
tests: [
'test/*.js',
Expand Down
5 changes: 4 additions & 1 deletion package.json
Expand Up @@ -12,10 +12,13 @@
"chai": "*",
"nixt": "*",
"istanbul": "~0.2.3",
"jack": "git://github.com/jackjs/jack.git#master",
"jack-chai": "~0.1.0",
"hydro": "*",
"hydro-doc": "0.0.2",
"hydro-bdd": "~0.1.0",
"hydro-chai": "~0.1.3"
"hydro-chai": "~0.1.3",
"hydro-jack": "0.0.1"
},
"repository": {
"type": "git",
Expand Down
103 changes: 103 additions & 0 deletions test/todos.js
@@ -0,0 +1,103 @@
var Todos = require('../lib/todos');
var Todo = require('../lib/todo');

var storage = { read: function() { return []; } };
var pending = { id: 1, status: 'pending', desc: 'desc', };
var completed = { id: 2, status: 'done', desc: 'desc' };
var data = [ pending, completed ];

describe(Todos, function() {
describe('#list', function() {
it('lists todo items with given status', function() {
jack(storage, 'read', function() { return data; });

var todos = new Todos(storage);
var items = todos.list('pending');

items.should.have.lengthOf(1);
items[0].id.should.eq(pending.id);
});
});

describe('#create', function() {
it('creates a new todo item', function() {
var todos = new Todos(storage);
jack(storage, 'write');

todos.create('desc');
storage.write.should.have.been.called.with.args([ new Todo(1, 'desc') ]);
});
});

describe('#check', function() {
it('completes todo items and persists them', function() {
var todos = new Todos(storage);

jack(storage, 'write');
jack(storage, 'read', function() { return [pending]; });

todos.check(pending.id);
storage.write.should.have.been.called.with.args([ new Todo(1, 'desc', 'done') ]);
});

it('errors when it cannot find the given todo item', function() {
var todos = new Todos(storage);
jack(storage, 'read', function() { return [pending]; });

should.throw(function() {
todos.check(completed.id);
});
});
});

describe('#undo', function() {
it('undoes todo items and persists them', function() {
var todos = new Todos(storage);

jack(storage, 'write');
jack(storage, 'read', function() { return [ completed ]; });

todos.undo(completed.id);
storage.write.should.have.been.called.with.args([ new Todo(2, 'desc', 'pending') ]);
});

it('errors when it cannot find the given todo item', function() {
var todos = new Todos(storage);
jack(storage, 'read', function() { return [ completed ]; });

should.throw(function() {
todos.undo(pending.id);
});
});
});

describe('#destroy', function() {
it('undoes todo items and persists them', function() {
var todos = new Todos(storage);

jack(storage, 'write');
jack(storage, 'read', function() { return [ pending, completed ]; });

todos.destroy(completed.id);
storage.write.should.have.been.called.with.args([ new Todo(1, 'desc', 'pending') ]);
});

it('errors when it cannot find the given todo item', function() {
var todos = new Todos(storage);
jack(storage, 'read', function() { return [ completed ]; });

should.throw(function() {
todos.destroy(pending.id);
});
});
});

describe('#clear', function() {
it('persists a blank todo list', function() {
var todos = new Todos(storage);
jack(storage, 'write');
todos.clear();
storage.write.should.have.been.called.with.args([]);
});
});
});

0 comments on commit 2b5947d

Please sign in to comment.