-
Notifications
You must be signed in to change notification settings - Fork 1
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
feature/router 라우터 기능 수정 및 테스트 코드 수정 #3
Conversation
devbit4
commented
Jan 12, 2024
•
edited
Loading
edited
- router 클래스로 변경 및 테스트코드 수정
- articleList.json 데이터 파일 추가 및 페이지 api 연동 테스트
|
} | ||
|
||
getArticle() { | ||
fetch('/dbs/articleList.json') |
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.
data fetching하는 부분을 함수로 분리하여 다음과 같은 형태로 쓸 수 있도록 만들어보면 좋을 것 같네요.
const article = await getArticle(this.props.params.id)
this.setState({ ...this.state, article })
}); | ||
} | ||
|
||
renderArticleList() { |
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.
Component의 render가 아닌 새로운 함수를 선언해서 렌더링하는 이유가 무엇인가요?
}, | ||
{ path: '*', page: jest.fn().mockReturnValue('<div>404-page</div>') }, | ||
]; | ||
class Home extends Component { |
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.
테스트를 위한 페이지 컴포너트를 이용하여 테스트하는 것도 필요하지만 실제 페이지 컴포넌트를 import하여 테스트하는 코드도 필요할 것 같습니다.
const router = new Router(target); | ||
|
||
beforeAll(() => { | ||
router |
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.
test가 돌 때마다 공통으로 초기화 해주어야 하는 부분인지 확인하고 사용하면 좋을 것 같습니다.
this.target = target; | ||
} | ||
|
||
addRoute(route) { |
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.
체이닝을 할 수 있는 형태로 만든건 좋네요!
Router 모듈과 컴포넌트 부분은 클래스를 사용하면서 이전보다 확실히 나아졌네요. 수고많으셨습니다. |