Skip to content

Commit

Permalink
test: getTimeDifference 테스트 코드 작성
Browse files Browse the repository at this point in the history
  • Loading branch information
zereight committed Jul 12, 2021
1 parent d23a239 commit 569e8a3
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions frontend/reply-module/src/__test__/unit/time.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// import "@testing-library/jest-dom/extend-expect";
// import { render } from "@testing-library/react";

import { getTimeDifference } from "../../utils/time";

describe("Time Util", () => {
test("getTimeDifference", () => {
const beforeThirtySeconds = new Date();
beforeThirtySeconds.setSeconds(beforeThirtySeconds.getSeconds() - 1);

const beforeOneMinute = new Date();
beforeOneMinute.setMinutes(beforeOneMinute.getMinutes() - 1);

const beforeOneHour = new Date();
beforeOneHour.setHours(beforeOneHour.getHours() - 1);

const beforeOneDay = new Date();
beforeOneDay.setDate(beforeOneDay.getDate() - 1);

const beforeOneWeek = new Date();
beforeOneWeek.setDate(beforeOneDay.getDate() - 7);

const beforeOneMonth = new Date();
beforeOneMonth.setMonth(beforeOneMonth.getMonth() - 1);

const beforeOneYear = new Date();
beforeOneYear.setFullYear(beforeOneYear.getFullYear() - 1);

expect(getTimeDifference(beforeThirtySeconds.toString())).toEqual("방금 전");
expect(getTimeDifference(beforeOneMinute.toString())).toEqual("1분 전");
expect(getTimeDifference(beforeOneHour.toString())).toEqual("1시간 전");
expect(getTimeDifference(beforeOneDay.toString())).toEqual("1일 전");
expect(getTimeDifference(beforeOneWeek.toString())).toEqual("1주 전");
expect(getTimeDifference(beforeOneMonth.toString())).toEqual("1개월 전");
expect(getTimeDifference(beforeOneYear.toString())).toEqual("1년 전");
});
});

0 comments on commit 569e8a3

Please sign in to comment.