Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions src/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ describe('ms(string)', () => {
expect(ms('1y')).toBe(31557600000);
});

it('should convert mo to ms', () => {
expect(ms('1mo')).toBe(2629800000);
});

it('should work with decimals', () => {
expect(ms('1.5h')).toBe(5400000);
});
Expand Down Expand Up @@ -116,6 +120,10 @@ describe('ms(long string)', () => {
expect(ms('1 week')).toBe(604800000);
});

it('should convert months to ms', () => {
expect(ms('1 month')).toBe(2629800000);
});

it('should convert years to ms', () => {
expect(ms('1 year')).toBe(31557600000);
});
Expand Down Expand Up @@ -329,6 +337,28 @@ describe('ms(number)', () => {
});
});

// zero

describe('ms(zero)', () => {
it('should handle zero as a string', () => {
expect(ms('0')).toBe(0);
});

it('should handle zero with unit', () => {
expect(ms('0ms')).toBe(0);
expect(ms('0s')).toBe(0);
expect(ms('0h')).toBe(0);
});

it('should handle zero as a number', () => {
expect(ms(0)).toBe('0ms');
});

it('should handle zero with long format', () => {
expect(ms(0, { long: true })).toBe('0 ms');
});
});

// invalid inputs

describe('ms(invalid inputs)', () => {
Expand Down