@gitsunmin/k-number
Version:
숫자를 입력하면 한글 수사를 반환하는 기능을 제공하는 라이브러리입니다. (ex. 1234 -> 천이백삼십
55 lines (54 loc) • 2.47 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const constants_1 = require("@/constants");
const errors_1 = require("@/errors");
const index_1 = require("@/k-number/index");
describe('invalid input', () => {
test('소수점이 포함된 숫자', () => {
expect((0, index_1.kNumber)(3.14)).toBe(errors_1.ErrorCollection.NOT_INTEGER);
});
test('지원하지 않는 포맷', () => {
// @ts-expect-error
expect((0, index_1.kNumber)(1234, { format: 'english-only' })).toBe(errors_1.ErrorCollection.INVALID_FORMAT);
});
test('숫자가 아닌 값을 입력받은 경우', () => {
// @ts-expect-error
expect((0, index_1.kNumber)('동해물과백두산이말라버렸다.')).toBe(errors_1.ErrorCollection.NOT_NUMBER);
});
test('최대 숫자를 넘긴 입력을 받은 경우', () => {
expect((0, index_1.kNumber)(constants_1.MAX_NUMBER + 1)).toBe(errors_1.ErrorCollection.OVER_MAX_NUMBER);
});
test('최소 숫자보다 낮은 입력을 받은 경우', () => {
expect((0, index_1.kNumber)(constants_1.MIN_NUMBER - 1)).toBe(errors_1.ErrorCollection.UNDER_MIN_NUMBER);
});
test('입력이 없는 경우', () => {
// @ts-expect-error
expect((0, index_1.kNumber)(undefined)).toBe(errors_1.ErrorCollection.NOT_NUMBER);
});
test('입력이 null 인 경우', () => {
// @ts-expect-error
expect((0, index_1.kNumber)(null)).toBe(errors_1.ErrorCollection.NOT_NUMBER);
});
test('custom error', () => {
const customError = 'custom error';
// @ts-expect-error
expect((0, index_1.kNumber)('동해물과백두산이말라버렸다.', { onError: () => customError })).toBe(customError);
});
test('custom error for 지원하지 않는 포맷', () => {
const customError = 'custom error';
expect((0, index_1.kNumber)(1234, {
// @ts-expect-error
format: 'english-only', onError: () => customError
})).toBe(customError);
});
test('custom error for 숫자가 아닌 값을 입력받은 경우', () => {
const customError = '숫자가 아닙니다.';
expect((0, index_1.kNumber)(3.14, {
// @ts-expect-error
onError: (error) => {
if (error === errors_1.ErrorCollection.NOT_INTEGER)
return customError;
}
})).toBe(customError);
});
});