add test for error when invalid unit used

This commit is contained in:
Michael Barrett 2014-07-18 09:25:12 +01:00
parent 60b303f7cb
commit 9099f90693
2 changed files with 12 additions and 5 deletions

View File

@ -3,7 +3,15 @@ var expect = chai.expect;
var timestring = require('../timestring');
describe('timestring', function() {
it('should expose a method on String.prototype that will attempt to parse the string as a timestring', function(done){
it('throws an error when an invalid unit is used in the timestring', function(done) {
var ts = new timestring();
expect(ts.parse.bind(ts, '1g')).to.throw(Error);
done();
});
it('should expose a method on String.prototype that will parse the string as a timestring', function(done){
var str = '1min';
// no arguments passed

View File

@ -12,8 +12,7 @@
// merge default settings with user settings
settings = settings || {};
this.settings = {};
for (var d in defaults) { this.settings[d] = defaults[d]; }
this.settings = defaults;
for (var s in settings) { this.settings[s] = settings[s]; }
// time units
@ -56,8 +55,8 @@
}
}
// throw exception if invalid unit is passed
throw 'The unit [' + unit + '] is not supported by timestring';
// throw error if invalid unit was passed
throw new Error('The unit [' + unit + '] is not supported by timestring');
}
// convert a value to a specific unit