diff --git a/test/timestring.js b/test/timestring.js index 8a54209..39301ee 100644 --- a/test/timestring.js +++ b/test/timestring.js @@ -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 diff --git a/timestring.js b/timestring.js index 281809f..bab6110 100644 --- a/timestring.js +++ b/timestring.js @@ -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