test: improve test structure

This commit is contained in:
Kim, Jimin 2023-07-31 00:52:51 +09:00
parent bd93b25dd2
commit a70b284b7c
Signed by: pomp
GPG key ID: CE1DDB8A4A765403

View file

@ -74,31 +74,29 @@ describe("getAge tests", () => {
expect(isOverBirthDay(date)).toEqual(testData.overBD) expect(isOverBirthDay(date)).toEqual(testData.overBD)
}) })
test("ageInt to work", () => { test.each<[string, number]>([
expect(ageInt(birth)).toEqual(0) ["2002-07-30 00:00:00.000+09:00", 0],
expect(ageInt(dayjs("2023-07-29"))).toEqual(20) ["2023-07-29 00:00:00.000+09:00", 20],
expect(ageInt(dayjs("2023-07-30"))).toEqual(21) ["2023-07-30 00:00:00.000+09:00", 21],
expect(ageInt(dayjs("2023-07-31"))).toEqual(21) ["2023-07-31 00:00:00.000+09:00", 21],
])("ageInt to work for '%s'", (date, expected) => {
expect(ageInt(dayjs(date))).toEqual(expected)
}) })
test("ageDecimal to work", () => { test.each<[string, number]>([
expect(ageDecimal(dayjs("2023-07-29 00:00:00.000+09:00"))).toEqual( ["2023-07-29 00:00:00.000+09:00", 0.9972602739726028],
0.9972602739726028 ["2023-07-30 00:00:00.000+09:00", 0.0],
) ["2023-07-31 00:00:00.000+09:00", 0.00273224043715847],
expect(ageDecimal(dayjs("2023-07-30 00:00:00.000+09:00"))).toEqual(0) ])("ageDecimal to work for '%s'", (date, expected) => {
expect(ageDecimal(dayjs("2023-07-31 00:00:00.000+09:00"))).toEqual( expect(ageDecimal(dayjs(date))).toEqual(expected)
0.00273224043715847
)
}) })
test("getAge to work", () => { test.each<[string, number]>([
expect(getAge(dayjs("2002-07-30 00:00:00.000+09:00"))).toEqual(0.0) ["2002-07-30 00:00:00.000+09:00", 0.0],
expect(getAge(dayjs("2023-07-29 00:00:00.000+09:00"))).toEqual( ["2023-07-29 00:00:00.000+09:00", 20.997260273972604],
20.997260273972604 ["2023-07-30 00:00:00.000+09:00", 21.0],
) ["2023-07-31 00:00:00.000+09:00", 21.002732240437158],
expect(getAge(dayjs("2023-07-30 00:00:00.000+09:00"))).toEqual(21.0) ])("getAge to work for '%s'", (date, expected) => {
expect(getAge(dayjs("2023-07-31 00:00:00.000+09:00"))).toEqual( expect(getAge(dayjs(date))).toEqual(expected)
21.002732240437158
)
}) })
}) })