Skip to content

Commit

Permalink
add test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
adoyle-h committed Sep 4, 2016
1 parent 204c951 commit 03993f2
Showing 1 changed file with 65 additions and 0 deletions.
65 changes: 65 additions & 0 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@ if ('undefined' != typeof require) {
// strings

describe('ms(string)', function(){
it('should not throw an error', function() {
expect(function() {
ms('1m');
}).to.not.throwError();
});

it('should preserve ms', function () {
expect(ms('100')).to.be(100);
});
Expand Down Expand Up @@ -59,6 +65,12 @@ describe('ms(string)', function(){
// long strings

describe('ms(long string)', function(){
it('should not throw an error', function() {
expect(function() {
ms('53 milliseconds');
}).to.not.throwError();
});

it('should convert milliseconds to ms', function () {
expect(ms('53 milliseconds')).to.be(53);
});
Expand Down Expand Up @@ -91,6 +103,12 @@ describe('ms(long string)', function(){
// numbers

describe('ms(number, { long: true })', function(){
it('should not throw an error', function() {
expect(function() {
ms(500, { long: true });
}).to.not.throwError();
});

it('should support milliseconds', function(){
expect(ms(500, { long: true })).to.be('500 ms');
})
Expand Down Expand Up @@ -127,6 +145,12 @@ describe('ms(number, { long: true })', function(){
// numbers

describe('ms(number)', function(){
it('should not throw an error', function() {
expect(function() {
ms(500);
}).to.not.throwError();
});

it('should support milliseconds', function(){
expect(ms(500)).to.be('500ms');
})
Expand Down Expand Up @@ -155,3 +179,44 @@ describe('ms(number)', function(){
expect(ms(234234234)).to.be('3d');
})
})


// invalid inputs

describe('ms(invalid inputs)', function() {
it('should throw an error, when ms("")', function() {
expect(function() {
ms('');
}).to.throwError();
});

it('should throw an error, when ms(undefined)', function() {
expect(function() {
ms(undefined);
}).to.throwError();
});

it('should throw an error, when ms(null)', function() {
expect(function() {
ms(null);
}).to.throwError();
});

it('should throw an error, when ms([])', function() {
expect(function() {
ms([]);
}).to.throwError();
});

it('should throw an error, when ms({})', function() {
expect(function() {
ms({});
}).to.throwError();
});

it('should throw an error, when ms(NaN)', function() {
expect(function() {
ms(NaN);
}).to.throwError();
});
});

0 comments on commit 03993f2

Please sign in to comment.