-
Notifications
You must be signed in to change notification settings - Fork 2
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
고생하셨습니다.. 테스트 넘나 어렵네요
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); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
저는 훅 자체를 그냥 목 으로 사용했는데 이렇게 하면 구체적으로 어떤 애니메이션을 호출해서 실행했는지까지도 테스트 할 수 있겠네요
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); | ||
}); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
저는 props 에 따른 랜더링테스트 test 하나에서 전부 했는데 랜더링 테스트를 분리해서 하나의 describe 에 넣는 방식도 좋은 것 같아요
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(), | ||
}; | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IntersectionObserver를 이렇게 테스트 할 수 있군요... 신기해요
act(() => { | ||
(IntersectionObserver as jest.Mock).mock.calls[0][0]([ | ||
{ isIntersecting: true }, | ||
]); | ||
}); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
콜백 호출 테스트를 이런식으로 해야 하는군요
복잡하네요..
🎯 이슈 번호
💡 작업 내용
💡 자세한 설명
테스트 코드 작성
📗 참고 자료 (선택)
jest mocking
jest mock, spyon
📢 리뷰 요구 사항 (선택)
🚩 후속 작업 (선택)
✅ 셀프 체크리스트