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

chore: migrate tests from karma to jest #79

Merged
merged 7 commits into from
Jul 1, 2021
Merged

Conversation

jajugoguma
Copy link
Contributor

Please check if the PR fulfills these requirements

  • It's submitted to right branch according to our branching model
  • It's right issue type on title
  • When resolving a specific issue, it's referenced in the PR's title (e.g. fix #xxx[,#xxx], where "xxx" is the issue number)
  • The commit message follows our guidelines
  • Tests for the changes have been added (for bug fixes/features)
  • Docs have been added/updated (for bug fixes/features)
  • It does not introduce a breaking change or has description for the breaking change

Description

  • remove karma-jasmine test environment
  • set jest test environment
  • tests migrate from jasmine to jest

Thank you for your contribution to TOAST UI product. 🎉 😘 ✨

Copy link

@adhrinae adhrinae left a comment

Choose a reason for hiding this comment

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

리뷰완료합니다 👏

Copy link

@dongsik-yoo dongsik-yoo left a comment

Choose a reason for hiding this comment

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

리뷰 완료합니다. 수고하셨습니다.

.gitignore에도 카르마로 생성되는 테스트 결과 폴더가 있으면 제거해 주세요.

package.json Outdated
@@ -41,19 +40,11 @@
"eslint-config-prettier": "^6.11.0",
"eslint-config-tui": "^2.2.0",
"eslint-loader": "^3.0.0",
"eslint-plugin-jest": "^24.3.6",
"eslint-plugin-prettier": "^3.1.3",
"file-loader": "^0.9.0",
"istanbul-instrumenter-loader": "^1.0.0",

Choose a reason for hiding this comment

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

이것도 카르마에서 사용되는 패키지라서 삭제해야 합니다. 다른 컴포넌트도 확인 부탁드립니다.

Choose a reason for hiding this comment

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

es5-shim도 필요없겠어요.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

모든 컴포넌트에 대해 사용하지 않는 패키지 삭제하도록 하겠습니다.

@@ -65,7 +66,7 @@ describe('DateRangePicker', function() {
it('should set null to end-date when changing start-date to a later date than end-date', function() {
picker.setStartDate(new Date(2017, 0, 20));

expect(picker.getEndDate()).toEqual(null);
expect(picker.getEndDate()).toBeNull();

Choose a reason for hiding this comment

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

getEndDate가 null일 수 있군요. index.d.ts에 타입 정의에서 리턴에 null도 추가해야겠어요. todo 리스트에 넣어 주세요.

public getEndDate: () => Date | null;

Copy link
Contributor

Choose a reason for hiding this comment

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

getStartDate도 추가되어야 하겠네요.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

네! todo list에 추가하도록 하겠습니다.

Copy link
Contributor

@lja1018 lja1018 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 22 to 27
body._dateLayer.changeLanguage = jest.fn();
body._monthLayer.changeLanguage = jest.fn();
body._yearLayer.changeLanguage = jest.fn();

body.changeLanguage('ko');
expect(body._dateLayer.changeLanguage).toHaveBeenCalledWith('ko');
Copy link

Choose a reason for hiding this comment

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

DOM 요소를 통해 검증하거나 다른 방법을 통해 검증할 수는 없을까요? 내부 구현에 너무 깊숙이 접근해서 검증하고 있어서요.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

render 메서드를 호출하는 것으로 DOM 요소를 생성하도록 했고, changeLanguage 메서드에 의해 한글로 변환되는 요소(date의 요일, month의 월)이 한글인지 toMatch matcher를 이용해 검증하는 것으로 변경했습니다.

Comment on lines 35 to 36
body._dateLayer.remove = jest.fn();
body._monthLayer.render = jest.fn();
Copy link

Choose a reason for hiding this comment

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

이 부분도 마찬가지네요. DOM 요소를 통해 검증할 수 있으면 좋을 것 같아요. 이런 테스트는 아무래도 내부 구현을 조금만 변경해도 다 깨질테니까요

Copy link
Contributor Author

Choose a reason for hiding this comment

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

render 메서드 호출 이전과 이후 DOM 요소를 비교해 검증하는 것으로 변경했습니다.

'December 2016'
);
});

it('should fire "click" custom event when click a button', function() {
var spy = jasmine.createSpy('button click handler');
var spy = jest.fn();
header.on('click', spy);

header._container.querySelector('.' + constants.CLASS_NAME_NEXT_MONTH_BTN).click();
Copy link

Choose a reason for hiding this comment

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

이런 코드는 함수로 추상화해서 사용하는 것도 좋겠어요~! (중간에 _container는 제거할 수 있음 제거해도 좋겠네요)

function clickBtnInHeader(className) {
  header._container.querySelector(`.${className}`).click();
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

말씀 해주신 것처럼 반복되는 동작에 대해 함수로 추상화 해서 사용하는 것으로 변경했습니다.

@@ -85,7 +85,8 @@ describe('Calendar', function() {
});

it('"changeLanaguage" should re-initilize formatters', function() {
Copy link

Choose a reason for hiding this comment

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

꼭 필요한 검증 사항인가요~?퍼블릭한 프로퍼티나 메서드로만 검증하는게 좋을 것 같아요.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

내부 메서드를 검증하는 불필요한 테스트 삭제했습니다.

Copy link

@js87zz js87zz left a comment

Choose a reason for hiding this comment

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

리뷰 완료입니다!

@jajugoguma jajugoguma merged commit 36811aa into master Jul 1, 2021
@jajugoguma jajugoguma deleted the chore/karma-to-jest branch July 1, 2021 02:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants