From 30a9f844c2461a5089ce21e0214ef062180a2b73 Mon Sep 17 00:00:00 2001 From: Mahmoud Hamdi Date: Mon, 30 Mar 2026 00:49:18 +0200 Subject: [PATCH] test: add missing month parsing and zero value coverage MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The ms(string) and ms(long string) test sections cover every unit (y, w, d, h, m, s, ms) except months — even though months are supported since v3 and tested in parse.test.ts. This adds the missing cases through the main ms() entry point. Also adds zero-value tests (ms('0'), ms('0ms'), ms(0), ms(0, {long})) which were previously untested. --- src/index.test.ts | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/src/index.test.ts b/src/index.test.ts index 5035ab9..5e21eb6 100644 --- a/src/index.test.ts +++ b/src/index.test.ts @@ -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); }); @@ -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); }); @@ -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)', () => {