Skip to content

Commit

Permalink
Added initial unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Aaron1011 committed Jul 15, 2013
1 parent eb7fbaf commit a100dfd
Show file tree
Hide file tree
Showing 4 changed files with 83 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .travis.yml
@@ -0,0 +1,5 @@
language: node_js
node_js:
- "0.6"
- "0.8"
- "0.10"
9 changes: 9 additions & 0 deletions Makefile
@@ -0,0 +1,9 @@
mocha = ../node_modules/.bin/mocha --reporter spec

test:
cd client && $(mocha)
cd server && $(mocha)

all: test

.PHONY: test
62 changes: 62 additions & 0 deletions client/test/chest.js
@@ -0,0 +1,62 @@
var requirejs = require('requirejs'),
should = require('should'),
sinon = require('sinon');
var globals = new Object();

requirejs.config({nodeRequire: require, baseUrl: 'js/'});

requirejs(['lib/class', '../../shared/js/gametypes'], function(_Class, _Types) {
globals.Class = _Class;
globals.Types = _Types;
global.window = globals
});

describe('Chest', function() {
var Chest;
var self = this;

beforeEach(function(done) {

requirejs(['chest'], function(_Module) {
Chest = _Module;
self.chest = new Chest(1);
done();
});
});


describe('#getSpriteName', function() {
it('should return "chest"', function() {
self.chest.getSpriteName().should.equal("chest");
});
});

describe('#isMoving', function() {
it('should return false', function() {
self.chest.isMoving().should.be.false
});
});

describe('#onOpen', function() {
it('sets open_callback to the passed function', function() {
var func = function() {};
self.chest.onOpen(func);
self.chest.open_callback.toString().should.equal(func.toString());
});
});

describe('#open', function() {
it('calls open_callback if set', function() {
var spy = sinon.spy();
self.chest.onOpen(spy);
self.chest.open();
spy.called.should.equal.true;
});

it('does not call open_callback if not set', function() {
var spy = sinon.spy(self.chest.open_callback);
self.chest.open();
spy.called.should.equal.false;
});
});
});
7 changes: 7 additions & 0 deletions package.json
Expand Up @@ -13,5 +13,12 @@
, "memcache": ">0"
, "redis": ">0"
, "connect": ">2"
, "mocha": ">1"
, "requirejs": ">2"
, "should": ">1"
, "sinon": ">1"
}
, "scripts": {
"test": "make test"
}
}

0 comments on commit a100dfd

Please sign in to comment.