Sha256: b9e846afbd289ce75b0fb41ebe953f94b1789d86de552620aad5e17b707f41f6

Contents?: true

Size: 1.96 KB

Versions: 9

Compression:

Stored size: 1.96 KB

Contents

/**
 * Dependencies.
 */

if ('undefined' != typeof require) {
  expect = require('expect.js');
  ms = require('../ms');
}

// 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 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);
  });
})

// numbers

describe('ms(number)', function(){
  it('should support milliseconds', function(){
    expect(ms(500)).to.be('500 ms');
  })

  it('should support seconds', function(){
    expect(ms(1000)).to.be('1 second');
    expect(ms(1500)).to.be('1.5 seconds');
    expect(ms(10000)).to.be('10 seconds');
  })

  it('should support minutes', function(){
    expect(ms(60 * 1000)).to.be('1 minute');
    expect(ms(60 * 1500)).to.be('1.5 minutes');
    expect(ms(60 * 10000)).to.be('10 minutes');
  })

  it('should support hours', function(){
    expect(ms(60 * 60 * 1000)).to.be('1 hour');
    expect(ms(60 * 60 * 1500)).to.be('1.5 hours');
    expect(ms(60 * 60 * 10000)).to.be('10 hours');
  })

  it('should support days', function(){
    expect(ms(24 * 60 * 60 * 1000)).to.be('1 day');
    expect(ms(24 * 60 * 60 * 1500)).to.be('1.5 days');
    expect(ms(24 * 60 * 60 * 10000)).to.be('10 days');
  })
})

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
stylus-source-0.34.1 vendor/node_modules/mocha/node_modules/ms/test/test.js
stylus-source-0.34.0 vendor/node_modules/mocha/node_modules/ms/test/test.js
stylus-source-0.33.1 vendor/node_modules/mocha/node_modules/ms/test/test.js
stylus-source-0.33.0 vendor/node_modules/mocha/node_modules/ms/test/test.js
stylus-source-0.32.1 vendor/node_modules/mocha/node_modules/ms/test/test.js
stylus-source-0.32.0 vendor/node_modules/mocha/node_modules/ms/test/test.js
stylus-source-0.31.0 vendor/node_modules/mocha/node_modules/ms/test/test.js
stylus-source-0.30.1 vendor/node_modules/mocha/node_modules/ms/test/test.js
stylus-source-0.30.0 vendor/node_modules/mocha/node_modules/ms/test/test.js