From ba05018003c6568992620a4b2174af981f0c7ab6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fredrik=20Adel=C3=B6w?= Date: Fri, 16 Jun 2023 12:18:46 +0200 Subject: [PATCH] add test MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Fredrik Adelöw --- packages/types/src/time.test.ts | 36 ++++++++++++++++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) diff --git a/packages/types/src/time.test.ts b/packages/types/src/time.test.ts index a1175c9e9b..7e85e46bfc 100644 --- a/packages/types/src/time.test.ts +++ b/packages/types/src/time.test.ts @@ -14,7 +14,7 @@ * limitations under the License. */ -import { HumanDuration } from './time'; +import { HumanDuration, durationToMilliseconds } from './time'; import { Duration } from 'luxon'; describe('time', () => { @@ -33,4 +33,38 @@ describe('time', () => { expect(Duration.fromObject(d).toObject()).toEqual(d); }); }); + + describe('durationToMilliseconds', () => { + it('converts a compound duration to milliseconds', () => { + const duration: HumanDuration = { + years: 1, + months: 1, + weeks: 1, + days: 1, + hours: 1, + minutes: 1, + seconds: 1, + milliseconds: 1, + }; + expect(durationToMilliseconds(duration)).toBe( + ((((365 + 30 + 7 + 1) * 24 + 1) * 60 + 1) * 60 + 1) * 1000 + 1, + ); + }); + + const durations: HumanDuration[] = [ + { years: 1 }, + { months: 1 }, + { weeks: 1 }, + { days: 1 }, + { hours: 1 }, + { minutes: 1 }, + { seconds: 1 }, + { milliseconds: 1 }, + ]; + it.each(durations)('computes milliseconds like luxon does, %p', d => { + expect(Duration.fromObject(d).as('milliseconds')).toEqual( + durationToMilliseconds(d), + ); + }); + }); });