Skip to content

Commit

Permalink
Merge pull request alexguan#43 from lightswitch05/feature/improve-cov…
Browse files Browse the repository at this point in the history
…erage

Improved code coverage
  • Loading branch information
alexguan authored Feb 10, 2017
2 parents 9eeb2e7 + 70f2b9f commit b462db5
Show file tree
Hide file tree
Showing 6 changed files with 360 additions and 3 deletions.
4 changes: 2 additions & 2 deletions lib/Exception.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ function validateCode(code) {
* @private
* @param code {Number} Exception code.
* @param name {String} Name of the exception.
* @param path {String} Node path of the exception, optional.
* @param ctor {String} The function to start in stack trace.
* @param [path] {String} Node path of the exception, optional.
* @param ctor {Function} The function to start in stack trace.
*/
function Exception(code, name, path, ctor) {
if (!ctor) {
Expand Down
12 changes: 11 additions & 1 deletion test/lib/Event.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ describe('Event', function () {
});

describe('toString', function () {
it('should return the correctly formatted string.', function () {
it('should return the correctly formatted string with a path.', function () {
var e = Event.create({
type : Event.NODE_CREATED,
path : '/test'
Expand All @@ -74,5 +74,15 @@ describe('Event', function () {
'NODE_CREATED[' + Event.NODE_CREATED + ']@/test'
);
});

it('should return the correctly formatted string without a path.', function () {
var e = Event.create({
type : Event.NODE_CREATED
});

expect(e.toString()).to.equal(
'NODE_CREATED[' + Event.NODE_CREATED + ']'
);
});
});
});
11 changes: 11 additions & 0 deletions test/lib/Exception.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,17 @@ var Exception = require('../../lib/Exception.js');


describe('Exception', function () {
it('does not require path', function () {
var exception = new Exception(0, 'name', function(){});
expect(exception.path).to.be.undefined;
});

it('requires ctor to be a function', function () {
expect(function () {
new Exception(0, 'name', null);
}).to.throw('ctor must be a function.');
});

describe('create', function () {
it('should only accept number code', function () {
expect(function () {
Expand Down
6 changes: 6 additions & 0 deletions test/lib/Path.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,5 +70,11 @@ describe('Path', function () {
Path.validate('/a..b');
}).to.not.throw('relative path');
});

it('should accept root path', function () {
expect(function () {
Path.validate('/');
}).to.not.throw('relative path');
});
});
});
15 changes: 15 additions & 0 deletions test/lib/State.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,20 @@ describe('State', function () {
expect(State.EXPIRED).to.exist;
});
});

it('gets the sate name', function () {
expect(State.DISCONNECTED.getName()).to.equal('DISCONNECTED');
});

it('gets the sate code', function () {
expect(State.DISCONNECTED.getCode()).to.equal(0);
});

it('represents the state as a string', function () {
var state = State.DISCONNECTED;
var expectedString = state.getName() + '[' + state.getCode() + ']';

expect(String(State.DISCONNECTED)).to.equal(expectedString);
});
});

Loading

0 comments on commit b462db5

Please sign in to comment.