Conversation
- IntersectionObserver 모킹하여 LazyImage 렌더링 상황 제어 - 초기 렌더링, 지연 로딩, 에러 핸들링, unmount 시 처리 테스트 - index, delayMs props에 따른 지연 로딩 테스트
|
""" Walkthrough이번 변경에서는 Changes
Sequence Diagram(s)sequenceDiagram
participant Test as LazyImage.test.tsx
participant LazyImage as LazyImage Component
participant MockIO as MockIntersectionObserver
participant DOM as DOM
Test->>LazyImage: 렌더링 요청 (props 전달)
LazyImage->>MockIO: IntersectionObserver 등록
MockIO-->>LazyImage: observe 콜백 호출 (intersecting 여부)
LazyImage->>DOM: placeholder 또는 이미지 렌더링
Test->>DOM: placeholder, 이미지, alt 속성 등 검증
Test->>LazyImage: unmount (컴포넌트 해제)
LazyImage->>MockIO: disconnect 호출
Assessment against linked issues
📜 Recent review detailsConfiguration used: CodeRabbit UI 📒 Files selected for processing (1)
🔇 Additional comments (2)
✨ Finishing Touches
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Pull Request Overview
This PR adds tests for the LazyImage component to verify its lazy loading behavior, IntersectionObserver integration, error handling, and proper unmounting.
- Added a data-testid attribute to the placeholder in LazyImage.tsx.
- Introduced comprehensive tests in LazyImage.test.tsx covering image loading, delay handling, IntersectionObserver callbacks, error propagation, and observer cleanup.
Reviewed Changes
Copilot reviewed 2 out of 4 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| frontend/src/components/common/LazyImage/LazyImage.tsx | Added data-testid for testing the placeholder element. |
| frontend/src/components/common/LazyImage/LazyImage.test.tsx | Added tests for lazy loading, delay behavior, IntersectionObserver integration, and onError behavior. |
Files not reviewed (2)
- frontend/package-lock.json: Language not supported
- frontend/package.json: Language not supported
✅ Deploy Preview for moadong ready!
To edit notification comments on pull requests, go to your Netlify site configuration. |

#️⃣연관된 이슈
📝작업 내용
@testing-library/jest-dom설치jest --coveragescripts에 추가jest 사용했을 때
jestdom 사용했을 때
적용 이유
LazyImage 테스트
IntersectionObserver에 대하여
가짜 함수
jest.fn()은 가짜함수를 만들어줍니다.만드는 이유는 테스트파일이 의존성을 줄이기 위해서입니다. 만약 테스트할 함수가 api 요청을 하는 함수라면
오로지 테스트를 위한 요청이 만들어집니다. 이는 불필요하기 때문에 가짜함수를 만들었습니다.
가짜 IntersectionObserver
IntersectionObserver가 없습니다.IntersectionObserver로 대체하여 프로젝트에서 컴포넌트가 정상적으로 동작하는지를 확인합니다.테스트
render: 말그대로 컴포넌트가 렌더링 되는지 확인합니다.참고자료
before/after
프론트엔드 테스트 | jest 기본 정리
waitFor을 통한 비동기 함수 테스트
jest 테스트 커버리지
중점적으로 리뷰받고 싶은 부분(선택)
논의하고 싶은 부분(선택)
🫡 참고사항
Summary by CodeRabbit
Summary by CodeRabbit