timestring/test/timestring.js

30 lines
747 B
JavaScript
Raw Normal View History

2014-07-18 00:13:01 +02:00
var chai = require('chai');
var expect = chai.expect;
var timestring = require('../timestring');
describe('timestring', function() {
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){
2014-07-18 00:13:01 +02:00
var str = '1min';
// no arguments passed
expect(str.parseTime()).to.equal(60);
// units argument passed
expect(str.parseTime('m')).to.equal(1);
// units + settings argument passed
str = '5h';
expect(str.parseTime('d', { hoursPerDay: 5 })).to.equal(1);
done();
});
});