|
1 | | -import { expect, test } from "vitest"; |
| 1 | +import { describe, expect, test } from "vitest"; |
2 | 2 | import escapeHtml from "."; |
3 | 3 |
|
4 | | -test("HTML 특수 문자를 이스케이프한다.", () => { |
5 | | - const input = "<span> 안녕하세요 </span>"; |
6 | | - const output = escapeHtml(input); |
7 | | - expect(output).toBe("<span> 안녕하세요 </span>"); |
| 4 | +describe("escapeHtml 유틸 함수 테스트", () => { |
| 5 | + test("HTML 특수 문자를 올바르게 이스케이프한다", () => { |
| 6 | + const input = "<span> 안녕하세요 </span>"; |
| 7 | + const output = escapeHtml(input); |
| 8 | + expect(output).toBe("<span> 안녕하세요 </span>"); |
| 9 | + }); |
| 10 | + |
| 11 | + test("여러 HTML 특수 문자를 포함한 문자열을 올바르게 이스케이프한다", () => { |
| 12 | + const input = "Tom & Jerry <3 \"Best Friends\" 'Forever' / Fun"; |
| 13 | + const output = escapeHtml(input); |
| 14 | + expect(output).toBe( |
| 15 | + "Tom & Jerry <3 "Best Friends" 'Forever' / Fun" |
| 16 | + ); |
| 17 | + }); |
| 18 | + |
| 19 | + test("HTML 특수 문자가 없는 문자열은 그대로 반환한다", () => { |
| 20 | + const input = "Hello World!"; |
| 21 | + const output = escapeHtml(input); |
| 22 | + expect(output).toBe("Hello World!"); |
| 23 | + }); |
| 24 | + |
| 25 | + test("빈 문자열을 입력하면 빈 문자열을 반환한다", () => { |
| 26 | + const input = ""; |
| 27 | + const output = escapeHtml(input); |
| 28 | + expect(output).toBe(""); |
| 29 | + }); |
| 30 | + |
| 31 | + test("null 또는 undefined를 입력하면 그대로 반환한다", () => { |
| 32 | + // @ts-ignore |
| 33 | + expect(escapeHtml(null)).toBe(null); |
| 34 | + // @ts-ignore |
| 35 | + expect(escapeHtml(undefined)).toBe(undefined); |
| 36 | + }); |
8 | 37 | }); |
0 commit comments