Debian Codegraph @

packages/babel-helper-validator-option/test/validator.spec.js

raw symbols SCIP
1 import { OptionValidator } from "../lib/index.js";
2
3 describe("OptionValidator", () => {
4 describe("validateTopLevelOptions", () => {
5 let v;
6 beforeAll(() => {
7 v = new OptionValidator("test-descriptor");
8 });
9 it("should throw when option key is not found", () => {
10 expect(() =>
11 v.validateTopLevelOptions(
12 { unknown: "options" },
13 { foo: "foo" },
14 "test",
15 ),
16 ).toThrow();
17 });
18 it("should throw when option key is an own property but not found", () => {
19 expect(() =>
20 v.validateTopLevelOptions(
21 { hasOwnProperty: "foo" },
22 {
23 foo: "foo",
24 bar: "bar",
25 aLongPropertyKeyToSeeLevenPerformance: "a",
26 },
27 "test",
28 ),
29 ).toThrow();
30 });
31 });
32 describe("validateBooleanOption", () => {
33 let v;
34 beforeAll(() => {
35 v = new OptionValidator("test-descriptor");
36 });
37 it("`undefined` option returns false", () => {
38 expect(v.validateBooleanOption("test", undefined, false)).toBe(false);
39 });
40
41 it("`false` option returns false", () => {
42 expect(v.validateBooleanOption("test", false, false)).toBe(false);
43 });
44
45 it("`true` option returns true", () => {
46 expect(v.validateBooleanOption("test", true, false)).toBe(true);
47 });
48
49 it("array option is invalid", () => {
50 expect(() => {
51 v.validateBooleanOption("test", [], false);
52 }).toThrow();
53 });
54 });
55
56 describe("validateStringOption", () => {
57 let v;
58 beforeAll(() => {
59 v = new OptionValidator("test-descriptor");
60 });
61 it("`undefined` option default", () => {
62 expect(v.validateStringOption("test", undefined, "default")).toBe(
63 "default",
64 );
65 });
66
67 it("`value` option returns value", () => {
68 expect(v.validateStringOption("test", "value", "default")).toBe("value");
69 });
70
71 it("no default returns undefined", () => {
72 expect(v.validateStringOption("test", undefined)).toBe(undefined);
73 });
74
75 it("array option is invalid", () => {
76 expect(() => {
77 v.validateStringOption("test", [], "default");
78 }).toThrow();
79 });
80 });
81 });