mirror of
https://github.com/monkeytypegame/monkeytype.git
synced 2025-11-09 13:44:29 +08:00
test: add unit tests for escapeHTML
This commit is contained in:
parent
5da0713209
commit
0d7d68f8b4
1 changed files with 41 additions and 1 deletions
|
|
@ -1,5 +1,5 @@
|
|||
import { describe, it, expect } from "vitest";
|
||||
import { getErrorMessage, isObject } from "../../src/ts/utils/misc";
|
||||
import { getErrorMessage, isObject, escapeHTML } from "../../src/ts/utils/misc";
|
||||
import {
|
||||
getLanguageDisplayString,
|
||||
removeLanguageSize,
|
||||
|
|
@ -123,6 +123,46 @@ describe("misc.ts", () => {
|
|||
});
|
||||
});
|
||||
|
||||
describe("escapeHTML", () => {
|
||||
it("should escape HTML characters correctly", () => {
|
||||
const tests = [
|
||||
{
|
||||
input: "hello world",
|
||||
expected: "hello world",
|
||||
},
|
||||
{
|
||||
input: "<script>alert('xss')</script>",
|
||||
expected: "<script>alert('xss')</script>",
|
||||
},
|
||||
{
|
||||
input: 'Hello "world" & friends',
|
||||
expected: "Hello "world" & friends",
|
||||
},
|
||||
{
|
||||
input: "Click `here` to continue",
|
||||
expected: "Click `here` to continue",
|
||||
},
|
||||
{
|
||||
input: null,
|
||||
expected: null,
|
||||
},
|
||||
{
|
||||
input: undefined,
|
||||
expected: undefined,
|
||||
},
|
||||
{
|
||||
input: "",
|
||||
expected: "",
|
||||
},
|
||||
];
|
||||
|
||||
tests.forEach((test) => {
|
||||
const result = escapeHTML(test.input);
|
||||
expect(result).toBe(test.expected);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe("getErrorMesssage", () => {
|
||||
it("should correctly get the error message", () => {
|
||||
const tests = [
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue