1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157
|
/**
* Dependencies.
*/
if ('undefined' != typeof require) {
expect = require('expect.js');
ms = require('../');
}
// strings
describe('ms(string)', function(){
it('should preserve ms', function () {
expect(ms('100')).to.be(100);
});
it('should convert from m to ms', function () {
expect(ms('1m')).to.be(60000);
});
it('should convert from h to ms', function () {
expect(ms('1h')).to.be(3600000);
});
it('should convert d to ms', function () {
expect(ms('2d')).to.be(172800000);
});
it('should convert s to ms', function () {
expect(ms('1s')).to.be(1000);
});
it('should convert ms to ms', function () {
expect(ms('100ms')).to.be(100);
});
it('should work with decimals', function () {
expect(ms('1.5h')).to.be(5400000);
});
it('should work with multiple spaces', function () {
expect(ms('1 s')).to.be(1000);
});
it('should return NaN if invalid', function () {
expect(isNaN(ms('☃'))).to.be(true);
});
it('should be case-insensitive', function () {
expect(ms('1.5H')).to.be(5400000);
});
it('should work with numbers starting with .', function () {
expect(ms('.5ms')).to.be(.5);
});
})
// long strings
describe('ms(long string)', function(){
it('should convert milliseconds to ms', function () {
expect(ms('53 milliseconds')).to.be(53);
});
it('should convert msecs to ms', function () {
expect(ms('17 msecs')).to.be(17);
});
it('should convert sec to ms', function () {
expect(ms('1 sec')).to.be(1000);
});
it('should convert from min to ms', function () {
expect(ms('1 min')).to.be(60000);
});
it('should convert from hr to ms', function () {
expect(ms('1 hr')).to.be(3600000);
});
it('should convert days to ms', function () {
expect(ms('2 days')).to.be(172800000);
});
it('should work with decimals', function () {
expect(ms('1.5 hours')).to.be(5400000);
});
})
// numbers
describe('ms(number, { long: true })', function(){
it('should support milliseconds', function(){
expect(ms(500, { long: true })).to.be('500 ms');
})
it('should support seconds', function(){
expect(ms(1000, { long: true })).to.be('1 second');
expect(ms(1200, { long: true })).to.be('1 second');
expect(ms(10000, { long: true })).to.be('10 seconds');
})
it('should support minutes', function(){
expect(ms(60 * 1000, { long: true })).to.be('1 minute');
expect(ms(60 * 1200, { long: true })).to.be('1 minute');
expect(ms(60 * 10000, { long: true })).to.be('10 minutes');
})
it('should support hours', function(){
expect(ms(60 * 60 * 1000, { long: true })).to.be('1 hour');
expect(ms(60 * 60 * 1200, { long: true })).to.be('1 hour');
expect(ms(60 * 60 * 10000, { long: true })).to.be('10 hours');
})
it('should support days', function(){
expect(ms(24 * 60 * 60 * 1000, { long: true })).to.be('1 day');
expect(ms(24 * 60 * 60 * 1200, { long: true })).to.be('1 day');
expect(ms(24 * 60 * 60 * 10000, { long: true })).to.be('10 days');
})
it('should round', function(){
expect(ms(234234234, { long: true })).to.be('3 days');
})
})
// numbers
describe('ms(number)', function(){
it('should support milliseconds', function(){
expect(ms(500)).to.be('500ms');
})
it('should support seconds', function(){
expect(ms(1000)).to.be('1s');
expect(ms(10000)).to.be('10s');
})
it('should support minutes', function(){
expect(ms(60 * 1000)).to.be('1m');
expect(ms(60 * 10000)).to.be('10m');
})
it('should support hours', function(){
expect(ms(60 * 60 * 1000)).to.be('1h');
expect(ms(60 * 60 * 10000)).to.be('10h');
})
it('should support days', function(){
expect(ms(24 * 60 * 60 * 1000)).to.be('1d');
expect(ms(24 * 60 * 60 * 10000)).to.be('10d');
})
it('should round', function(){
expect(ms(234234234)).to.be('3d');
})
})
|