frontity
Version:
Frontity cli and entry point to other packages
62 lines (49 loc) • 1.77 kB
text/typescript
import decodeServer from "../server";
import decodeClient from "../client";
import * as he from "he";
jest.mock("he");
const mockedHe = he as jest.Mocked<typeof he>;
describe("decode", () => {
beforeEach(() => {
mockedHe.decode.mockReset();
mockedHe.decode.mockImplementation(jest.requireActual("he").decode);
});
test("works on server", () => {
const result = decodeServer("&");
expect(result).toBe("&");
});
test("works on client", () => {
const result = decodeClient("&");
expect(result).toBe("&");
});
test("decodes numeric entities", () => {
const numeric = "blog’s";
const client = decodeClient(numeric);
expect(client).toBe("blog’s");
const server = decodeServer(numeric);
expect(server).toBe("blog’s");
});
test("client preserves the whitespace", () => {
const result = decodeClient(" & ");
expect(result).toBe(" & ");
});
test("server preserves the whitespace", () => {
const result = decodeServer(" & ");
expect(result).toBe(" & ");
});
test("handles different characters", () => {
const client = decodeClient("≡ γ ’");
expect(client).toBe("≡ γ ’");
const server = decodeServer("≡ γ ’");
expect(server).toBe("≡ γ ’");
});
test("call he.decode if html contains a character that basic decode cannot not handle", () => {
decodeServer(" ℬ");
expect(mockedHe.decode).toHaveBeenCalledTimes(1);
});
test("does not call he.decode if html contains a character that we can handle with basic decode", () => {
const result = decodeServer(" & '");
expect(result).toBe(" & '");
expect(mockedHe.decode).toHaveBeenCalledTimes(0);
});
});