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: internal 테스트 코드를 작성합니다 #137

Merged
merged 3 commits into from
Jun 29, 2024
Merged
Changes from all 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
61 changes: 61 additions & 0 deletions src/_internal/index.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import assert, { excludeLastElement, isBlank, joinString } from './index';

describe('excludeLastElement', () => {
it('마지막 요소를 제외한 모든 요소와 마지막 요소를 반환한다', () => {
const result = excludeLastElement(['apple', 'banana', 'cherry']);

expect(result).toEqual([['apple', 'banana'], 'cherry']);
});

it('입력 배열이 비어 있으면 빈 배열과 빈 문자열을 반환한다', () => {
const result = excludeLastElement([]);

expect(result).toEqual([[], '']);
});

it('배열에 단 하나의 요소만 있는 경우, 빈배열과 그 요소를 반환한다', () => {
const result = excludeLastElement(['apple']);

expect(result).toEqual([[], 'apple']);
});
});

describe('joinString', () => {
it('여러 문자열을 하나의 문자열로 연결한다', () => {
const result = joinString('Hello', ' ', 'World');

expect(result).toBe('Hello World');
});

it('인자가 주어지지 않았을 때 빈 문자열을 반환한다', () => {
const result = joinString();

expect(result).toBe('');
});
});

describe('isBlank', () => {
it('문자가 공백이면 true를 반환한다', () => {
expect(isBlank(' ')).toBe(true);
});

it('문자가 공백이 아니면 false를 반환한다', () => {
expect(isBlank('a')).toBe(false);
});
});

describe('assert', () => {
it('조건이 참이면 에러를 던지지 않는다', () => {
expect(() => assert(true)).not.toThrowError();
});

it('조건이 거짓이면 에러를 던진다', () => {
expect(() => assert(false)).toThrowError('Invalid condition');
});

it('조건이 거짓이고 에러 메시지가 제공된 경우 사용자 정의 에러 메시지를 던져야 한다', () => {
const customMessage = 'Custom error message';

expect(() => assert(false, customMessage)).toThrowError(customMessage);
});
});