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

test: amountToHangul 테스트 추가 #135

Merged
merged 7 commits into from
Jul 3, 2024
Merged
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/amountToHangul.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,9 @@ describe('amountToHangul', () => {
expect(amountToHangul('100000000')).toEqual('일억');
expect(amountToHangul('100000100')).toEqual('일억백');
});

it('숫자로 된 금액이 80글자를 넘을 시 에러 발생', () => {
const longNumberString = '1'.repeat(81);
assert.throws(() => amountToHangul(longNumberString), Error, `convert range exceeded : ${longNumberString}`);
Copy link
Member

Choose a reason for hiding this comment

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

이 프로젝트에서 사용하는 vitest가 제공해주는 toThrow 메서드가 아닌, assert를 사용하면 어떠한 이점이 있나요?
제가 생각한건 다음과 같아요.

 expect(() => amountToHangul(longNumberString)).toThrow(`convert range exceeded : ${longNumberString}`);
  });

Copy link
Contributor Author

Choose a reason for hiding this comment

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

특별한 이점은 없고 combineHangulCharacter.spec.ts, hangul.spec.ts에서 node 기본 모듈인 assert의 throws 메서드를 사용하다보니 동일하게 사용하려고 했습니다. vitest에서 제공해주는 toThrow 메서드를 사용하는 것이 일관성이 있을 것 같아요 !

combineHangulCharacter.spec.ts, hangul.spec.ts에서도 assert.throws대신 toThrow 메서드를 사용하도록 변경되면 좋을 것 같은데 추가로 PR 올려도 괜찮을까요 ?

Copy link
Collaborator

@po4tion po4tion Jun 30, 2024

Choose a reason for hiding this comment

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

@okinawaa 님 이건 좀 다른 주제이긴 한데요. vitest에서 제공하는 toThrowtoThrowError의 별칭인데요. 현재 테스트 코드 대다수에서 toThrowError를 사용하고 있는데 하나로 통일하여 일관성을 지키는게 좋지 않을까 싶은데 어떠신가요?

image

Copy link
Contributor Author

Choose a reason for hiding this comment

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

vitest-dev/vitest#2570

두 메서드는 동일하지만 error를 테스트할때 toThrowError를 사용하는 것이 직관적이겠네요 !

});
});