forked from PaloAltoNetworks/docusaurus-openapi-docs
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.test.ts
More file actions
68 lines (57 loc) · 1.94 KB
/
utils.test.ts
File metadata and controls
68 lines (57 loc) · 1.94 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
/* ============================================================================
* Copyright (c) Palo Alto Networks
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
* ========================================================================== */
import { guard, create, render } from "./utils";
describe("guard", () => {
it("should guard empty strings", () => {
const actual = guard("", (_) => {
throw new Error("Should not be called");
});
expect(actual).toBe("");
});
it("should guard undefined", () => {
const actual = guard(undefined, (value) => {
throw new Error("Should not be called");
});
expect(actual).toBe("");
});
it("should guard false booleans", () => {
const actual = guard(false, (value) => `${value}`);
expect(actual).toBe("");
});
it("should not guard strings", () => {
const actual = guard("hello", (value) => value);
expect(actual).toBe("hello");
});
it("should not guard numbers", () => {
const actual = guard(1, (value) => `${value}`);
expect(actual).toBe("1");
});
it("should not guard numbers equals to 0", () => {
const actual = guard(0, (value) => `${value}`);
expect(actual).toBe("0");
});
it("should not guard true booleans", () => {
const actual = guard(true, (value) => `${value}`);
expect(actual).toBe("true");
});
});
describe("create", () => {
it("should create element with props and children", () => {
const actual = create("div", { className: "x", children: "hello" });
expect(actual).toBe('<div className={"x"}>hello</div>');
});
});
describe("render", () => {
it("should render arrays while filtering undefined", () => {
const actual = render(["a", undefined, "b"]);
expect(actual).toBe("ab");
});
it("should render undefined as empty string", () => {
const actual = render(undefined);
expect(actual).toBe("");
});
});