javascript-time-ago
Version:
Localized relative date/time formatting
47 lines (46 loc) • 2.45 kB
JavaScript
;
var _mocha = require("mocha");
var _chai = require("chai");
var _getStep = _interopRequireDefault(require("./getStep.js"));
var _approximate = _interopRequireDefault(require("./approximate.js"));
function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
(0, _mocha.describe)('steps/approximate', function () {
(0, _mocha.it)('should get step correctly', function () {
var getStepFor = function getStepFor(secondsPassed) {
return (0, _getStep["default"])(_approximate["default"], secondsPassed, {
now: 0,
units: ['now', 'second', 'minute', 'hour', 'day', 'week', 'month', 'year']
});
};
(0, _chai.expect)(getStepFor(0).unit).to.equal('now');
(0, _chai.expect)(getStepFor(1).unit).to.equal('now');
(0, _chai.expect)(getStepFor(45).unit).to.equal('now');
(0, _chai.expect)(getStepFor(46).unit).to.equal('minute');
(0, _chai.expect)(getStepFor(46).factor).to.equal(60);
(0, _chai.expect)(getStepFor(46).granularity).to.be.undefined;
(0, _chai.expect)(getStepFor(2.5 * 60 - 1).unit).to.equal('minute');
(0, _chai.expect)(getStepFor(2.5 * 60 - 1).factor).to.equal(60);
(0, _chai.expect)(getStepFor(2.5 * 60 - 1).granularity).to.be.undefined;
(0, _chai.expect)(getStepFor(2.5 * 60).unit).to.equal('minute');
(0, _chai.expect)(getStepFor(2.5 * 60).factor).to.equal(60);
(0, _chai.expect)(getStepFor(2.5 * 60).granularity).to.equal(5);
(0, _chai.expect)(getStepFor(52.5 * 60 - 1).unit).to.equal('minute');
(0, _chai.expect)(getStepFor(52.5 * 60 - 1).factor).to.equal(60);
(0, _chai.expect)(getStepFor(52.5 * 60 - 1).granularity).to.equal(5);
(0, _chai.expect)(getStepFor(52.5 * 60).unit).to.equal('hour');
(0, _chai.expect)(getStepFor(52.5 * 60).factor).to.equal(60 * 60);
});
(0, _mocha.it)('should get step correctly ("now" unit not allowed)', function () {
var getStepFor = function getStepFor(secondsPassed) {
return (0, _getStep["default"])(_approximate["default"], secondsPassed, {
now: 0,
units: ['second', 'minute', 'hour', 'day', 'week', 'month', 'year']
});
};
(0, _chai.expect)(getStepFor(0)).to.be.undefined;
(0, _chai.expect)(getStepFor(1).unit).to.equal('second');
(0, _chai.expect)(getStepFor(45).unit).to.equal('second');
(0, _chai.expect)(getStepFor(46).unit).to.equal('minute');
});
});
//# sourceMappingURL=approximate.test.js.map