From 78425f1115e137f510dd8b2b50421192b11a30bd Mon Sep 17 00:00:00 2001 From: Bastian Meissner Date: Wed, 20 Apr 2022 12:29:00 +0200 Subject: [PATCH] Remove greeter snapshot test --- src/components/greeter.tsx | 3 +- .../__snapshots__/greeter.spec.tsx.snap | 21 ------------- src/test/components/greeter.spec.tsx | 30 +++++++++++++++++-- 3 files changed, 29 insertions(+), 25 deletions(-) diff --git a/src/components/greeter.tsx b/src/components/greeter.tsx index 1f49a15..1ef966f 100644 --- a/src/components/greeter.tsx +++ b/src/components/greeter.tsx @@ -94,8 +94,9 @@ export const getDateString = ( weekdays: Array, months: Array, format: string, + date?: Date, ) => { - const currentDate = new Date(); + const currentDate = date ? date : new Date(); const weekday = weekdays[currentDate.getDay()]; const day = currentDate.getDate(); diff --git a/src/test/components/__snapshots__/greeter.spec.tsx.snap b/src/test/components/__snapshots__/greeter.spec.tsx.snap index 42cfd28..47b950a 100644 --- a/src/test/components/__snapshots__/greeter.spec.tsx.snap +++ b/src/test/components/__snapshots__/greeter.spec.tsx.snap @@ -1,26 +1,5 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`Greeter snapshot test with properties 1`] = ` - -
-
-

- Wednesday, April 20th 2022 -

-

- Good afternoon! -

-
-
- -`; - exports[`Greeter snapshot test without properties 1`] = `
diff --git a/src/test/components/greeter.spec.tsx b/src/test/components/greeter.spec.tsx index e1cad3f..6b1b0a5 100644 --- a/src/test/components/greeter.spec.tsx +++ b/src/test/components/greeter.spec.tsx @@ -3,6 +3,7 @@ import Greeter, { IGreeterProps, isBetween, getExtension, + getDateString, } from "../../components/greeter"; const props: IGreeterProps = { @@ -98,9 +99,32 @@ it("getExtension test", () => { expect(getExtension(31)).toEqual("st"); }); -it("Greeter snapshot test with properties", () => { - const { baseElement } = render(); - expect(baseElement).toMatchSnapshot(); +it("getDateString Test", () => { + let dates: [Date] = [ + new Date("2022-04-04T00:00:00"), + new Date("2022-04-05T00:00:00"), + new Date("2022-04-06T00:00:00"), + new Date("2022-04-07T00:00:00"), + new Date("2022-04-08T00:00:00"), + new Date("2022-04-09T00:00:00"), + new Date("2022-04-10T00:00:00"), + ]; + + let results: [string] = [ + "Monday, April 4th 2022", + "Tuesday, April 5th 2022", + "Wednesday, April 6th 2022", + "Thursday, April 7th 2022", + "Friday, April 8th 2022", + "Saturday, April 9th 2022", + "Sunday, April 10th 2022", + ]; + + for (var i = 0; i < dates.length; i++) { + expect( + getDateString(props.days, props.months, props.dateformat, dates[i]), + ).toEqual(results[i]); + } }); it("Greeter snapshot test without properties", () => {