Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Refactor] 차량 소개, 선착순 이벤트, 인증 모달 관련 테스트 코드 작성 및 리팩토링 #78

Merged
merged 12 commits into from
Aug 19, 2024

Conversation

jw0097
Copy link
Collaborator

@jw0097 jw0097 commented Aug 19, 2024

🎯 이슈 번호

💡 작업 내용

  • 차량 소개 페이지 테스트 코드 작성 및 리팩토링
  • 선착순 이벤트 페이지 테스트 코드 작성 및 리팩토링
  • 인증 모달 페이지 테스트 코드 작성 및 리팩토링

💡 자세한 설명

테스트 코드 작성

📗 참고 자료 (선택)

jest mocking
jest mock, spyon

📢 리뷰 요구 사항 (선택)

🚩 후속 작업 (선택)

✅ 셀프 체크리스트

  • PR 제목을 형식에 맞게 작성했나요?
  • 브랜치 전략에 맞는 브랜치에 PR을 올리고 있나요? (master/main이 아닙니다.)
  • Reviewers, Labels, Projects를 등록했나요?
  • 작업 도중 문서 수정이 필요한 경우 잘 수정했나요?
  • 테스트는 잘 통과했나요?
  • 불필요한 코드는 제거했나요?

@jw0097 jw0097 added 🔨 Refactor Code refactoring ✅ Test For test labels Aug 19, 2024
@jw0097 jw0097 added this to the 코드 리팩토링 milestone Aug 19, 2024
@jw0097 jw0097 requested a review from leve68 August 19, 2024 01:21
@jw0097 jw0097 self-assigned this Aug 19, 2024
Copy link
Member

@leve68 leve68 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

고생하셨습니다.. 테스트 넘나 어렵네요

Comment on lines +44 to +55
await Promise.all(
glowElemntArray.map((glowElemnt, index) => {
expect(glowElemnt.animate).toHaveBeenCalledWith(fadeIn, {
...glowFadeOptions,
delay: (index + 1) * 1000,
});
}),
);

glowElemntArray.map((glowElemnt) => {
expect(glowElemnt.animate).toHaveBeenCalledWith(randomGlow, glowOptions);
});
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

저는 훅 자체를 그냥 목 으로 사용했는데 이렇게 하면 구체적으로 어떤 애니메이션을 호출해서 실행했는지까지도 테스트 할 수 있겠네요

Comment on lines +11 to +32
describe("ConvenienceDescriptionItem 렌더링 테스트", () => {
test("props로 전달받은 제목이 렌더링 되야 한다.", () => {
render(<ConvenienceDescriptionItem {...defaultProps} />);

const title = screen.getByText(defaultProps.title);
expect(title).toBeInTheDocument();
});

test("props로 전달받은 설명이 렌더링 되야 한다.", () => {
render(<ConvenienceDescriptionItem {...defaultProps} />);

const description = screen.getByText(defaultProps.description);
expect(description).toBeInTheDocument();
});

test("props로 전달받은 이미지가 렌더링 되야 한다.", () => {
render(<ConvenienceDescriptionItem {...defaultProps} />);

const image = screen.getByRole("img");
expect(image).toHaveAttribute("src", defaultProps.img);
});
});
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

저는 props 에 따른 랜더링테스트 test 하나에서 전부 했는데 랜더링 테스트를 분리해서 하나의 describe 에 넣는 방식도 좋은 것 같아요

Comment on lines +6 to +20
IntersectionObserver = jest.fn().mockImplementation((callback) => {
return {
observe: jest.fn((element) => {
callback([
{
isIntersecting: false,
target: element,
intersectionRect: { top: 0, left: 0 },
},
]);
}),
unobserve: jest.fn(),
disconnect: jest.fn(),
};
});
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IntersectionObserver를 이렇게 테스트 할 수 있군요... 신기해요

Comment on lines +46 to +51
act(() => {
(IntersectionObserver as jest.Mock).mock.calls[0][0]([
{ isIntersecting: true },
]);
});

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

콜백 호출 테스트를 이런식으로 해야 하는군요
복잡하네요..

@leve68 leve68 merged commit 813f125 into develop Aug 19, 2024
1 check passed
@leve68 leve68 deleted the feature/test-refactor branch August 19, 2024 05:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🔨 Refactor Code refactoring ✅ Test For test
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants