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,14 +8,13 @@ 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,
@ -65,16 +64,13 @@ describe("getAge tests", () => {
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", () => {