Skip to content

Commit

Permalink
test: jest 환경에서 시간대를 한국 시간대를 사용하도록 변경
Browse files Browse the repository at this point in the history
  • Loading branch information
pp449 committed Oct 15, 2024
1 parent 20d2f4c commit 02f8671
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 18 deletions.
1 change: 1 addition & 0 deletions frontend/jest.setup.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const { server } = require("@/mocks/server");

jest.mock("@/assets", () => "");
process.env.TZ = "Asia/Seoul";

// 모든 테스트 전에 MSW 서버를 시작합니다.
beforeAll(() => server.listen());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,8 @@ const mockBaseRoomInfo: RoomInfo = {

describe("RoomInfoCard 컴포넌트 테스트", () => {
beforeAll(() => {
const mockDate = new Date("2024-10-02T10:30:00+09:00");
const OriginalDate = Date;

jest.spyOn(global, "Date").mockImplementation((value) => {
return value ? new OriginalDate(value) : new OriginalDate(mockDate);
});
jest.useFakeTimers();
jest.setSystemTime(new Date("2024-10-02T10:30:00"));
});

it("'모집'중인 방에 2일 이상 남으면 '리뷰 마감까지 남은 일', '모집 마감까지 남은 일'이 보인다", async () => {
Expand Down
8 changes: 2 additions & 6 deletions frontend/src/components/shared/roomCard/RoomCard.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,8 @@ const mockBaseRoomInfo: RoomInfo = {

describe("RoomCard 컴포넌트 테스트", () => {
beforeAll(() => {
const mockDate = new Date("2024-10-02T10:30:00+09:00");
const OriginalDate = Date;

jest.spyOn(global, "Date").mockImplementation((value) => {
return value ? new OriginalDate(value) : new OriginalDate(mockDate);
});
jest.useFakeTimers();
jest.setSystemTime(new Date("2024-10-02T10:30:00"));
});

it("'모집'중인 방이 2일 이상 남으면 '모집마감 D-N'이 보인다", async () => {
Expand Down
8 changes: 2 additions & 6 deletions frontend/src/utils/dateFormatter.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,8 @@ import {

describe("날짜 포메팅 유틸 함수 테스트", () => {
beforeAll(() => {
const mockDate = new Date("2024-10-02T10:30:00+09:00");
const OriginalDate = Date;

jest.spyOn(global, "Date").mockImplementation((value) => {
return value ? new OriginalDate(value) : new OriginalDate(mockDate);
});
jest.useFakeTimers();
jest.setSystemTime(new Date("2024-10-02T10:30:00"));
});

afterAll(() => {
Expand Down

0 comments on commit 02f8671

Please sign in to comment.