Skip to content

Commit

Permalink
added unit test for exceptions (#24)
Browse files Browse the repository at this point in the history
  • Loading branch information
stanleyhlng authored Dec 13, 2016
1 parent 925f61f commit 716ba82
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@
"jenkins-mocha": "^2.6.0",
"mocha": "^3.1.2",
"mocha-lcov-reporter": "^1.2.0",
"pre-commit": "^1.1.3"
"pre-commit": "^1.1.3",
"sinon": "^1.17.6"
},
"keywords": [
"mocha",
Expand Down
27 changes: 27 additions & 0 deletions tests/lib/MultiReporters.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
var _require = require('root-require');
var expect = require('chai').expect;
var Mocha = require('mocha');
var sinon = require('sinon');
var Suite = Mocha.Suite;
var Runner = Mocha.Runner;
var Test = Mocha.Test;
Expand Down Expand Up @@ -133,6 +134,32 @@ describe('lib/MultiReporters', function () {
});
});
});

describe('#exception', function () {
var err;
beforeEach(function () {
err = new Error('JSON.parse error!');
sinon.stub(JSON, 'parse').throws(err);
});

afterEach(function () {
JSON.parse.restore();
});

it('throw an exception in default options', function () {
expect(JSON.parse.callCount).to.equal(0);
expect(reporter.getDefaultOptions.bind(this)).to.throw(err);
expect(JSON.parse.threw()).to.equal(true);
expect(JSON.parse.callCount).to.equal(1);
});

it('throw an exception in custom options', function () {
expect(JSON.parse.callCount).to.equal(0);
expect(reporter.getCustomOptions.bind(this, options)).to.throw(err);
expect(JSON.parse.threw()).to.equal(true);
expect(JSON.parse.callCount).to.equal(1);
});
});
});

describe('#test', function () {
Expand Down

0 comments on commit 716ba82

Please sign in to comment.