From c3eac3d27be60638df759ab57176f4e1e7314112 Mon Sep 17 00:00:00 2001 From: Daniel Ruf Date: Thu, 2 May 2019 20:57:42 +0200 Subject: [PATCH] test: fix formatDateDistance test (#43) Test formatDateDistance with a date which is about 2 months in the past and another which is exactly 2 months in the past. --- test/unit/utils/package.spec.js | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/test/unit/utils/package.spec.js b/test/unit/utils/package.spec.js index c6724cd..cf11498 100644 --- a/test/unit/utils/package.spec.js +++ b/test/unit/utils/package.spec.js @@ -52,13 +52,21 @@ describe('formatDate', () => { describe('formatDateDistance', () => { test('should calculate the distance', () => { + const dateAboutTwoMonthsAgo = () => { + const date = new Date(); + date.setMonth(date.getMonth() - 1); + date.setDate(date.getDay() - 20); + return date; + }; const dateTwoMonthsAgo = () => { const date = new Date(); date.setMonth(date.getMonth() - 2); return date; }; - const date = dateTwoMonthsAgo(); - expect(formatDateDistance(date)).toEqual('about 2 months'); + const date1 = dateAboutTwoMonthsAgo(); + const date2 = dateTwoMonthsAgo(); + expect(formatDateDistance(date1)).toEqual('about 2 months'); + expect(formatDateDistance(date2)).toEqual('2 months'); }); });