test: improve test structure

This commit is contained in:
Kim, Jimin 2023-07-30 21:58:59 +09:00
parent d4cf3e8de6
commit 08a0f967e3
Signed by: pomp
GPG key ID: CE1DDB8A4A765403

View file

@ -8,73 +8,69 @@ describe("getAge tests", () => {
expect(birth).toEqual(new Date("2002-07-30, 00:00:00.000 +09:00")) expect(birth).toEqual(new Date("2002-07-30, 00:00:00.000 +09:00"))
}) })
test("isOverBirthDay to work", () => { test.each<{
const testCases: { timestamp: string
timestamp: string overBD: boolean
overBD: boolean year: number
year: number monthIndex: number
monthIndex: number date: number
date: number }>([
}[] = [ {
{ timestamp: "2022-12-31, 00:00:00.000 +09:00",
timestamp: "2022-12-31, 00:00:00.000 +09:00", overBD: true,
overBD: true, year: 2022,
year: 2022, monthIndex: 11,
monthIndex: 11, date: 31,
date: 31, },
}, {
{ timestamp: "2023-01-01, 00:00:00.000 +09:00",
timestamp: "2023-01-01, 00:00:00.000 +09:00", overBD: false,
overBD: false, year: 2023,
year: 2023, monthIndex: 0,
monthIndex: 0, date: 1,
date: 1, },
}, {
{ timestamp: "2023-07-29, 00:00:00.000 +09:00",
timestamp: "2023-07-29, 00:00:00.000 +09:00", overBD: false,
overBD: false, year: 2023,
year: 2023, monthIndex: 6,
monthIndex: 6, date: 29,
date: 29, },
}, {
{ timestamp: "2023-07-30, 00:00:00.000 +09:00",
timestamp: "2023-07-30, 00:00:00.000 +09:00", overBD: true,
overBD: true, year: 2023,
year: 2023, monthIndex: 6,
monthIndex: 6, date: 30,
date: 30, },
}, {
{ timestamp: "2023-07-31, 00:00:00.000 +09:00",
timestamp: "2023-07-31, 00:00:00.000 +09:00", overBD: true,
overBD: true, year: 2023,
year: 2023, monthIndex: 6,
monthIndex: 6, date: 31,
date: 31, },
}, {
{ timestamp: "2023-12-31, 00:00:00.000 +09:00",
timestamp: "2023-12-31, 00:00:00.000 +09:00", overBD: true,
overBD: true, year: 2023,
year: 2023, monthIndex: 11,
monthIndex: 11, date: 31,
date: 31, },
}, {
{ timestamp: "2024-01-01, 00:00:00.000 +09:00",
timestamp: "2024-01-01, 00:00:00.000 +09:00", overBD: false,
overBD: false, year: 2024,
year: 2024, monthIndex: 0,
monthIndex: 0, date: 1,
date: 1, },
}, ])("isOverBirthDay to work ($timestamp)", (testData) => {
] const date = new Date(testData.timestamp)
for (const testCase of testCases) { expect(date.getFullYear()).toEqual(testData.year)
const date = new Date(testCase.timestamp) expect(date.getMonth()).toEqual(testData.monthIndex)
expect(date.getDate()).toEqual(testData.date)
expect(date.getFullYear()).toEqual(testCase.year) expect(isOverBirthDay(date)).toEqual(testData.overBD)
expect(date.getMonth()).toEqual(testCase.monthIndex)
expect(date.getDate()).toEqual(testCase.date)
expect(isOverBirthDay(date)).toEqual(testCase.overBD)
}
}) })
test("dateFormatOption to work properly", () => { test("dateFormatOption to work properly", () => {