massive update, probably broken
[dotfiles/.git] / .config / coc / extensions / node_modules / coc-prettier / node_modules / @humanwhocodes / object-schema / tests / validation-strategy.js
1 /**
2  * @filedescription Merge Strategy Tests
3  */
4 /* global it, describe, beforeEach */
5
6 "use strict";
7
8 //-----------------------------------------------------------------------------
9 // Requirements
10 //-----------------------------------------------------------------------------
11
12 const assert = require("chai").assert;
13 const { ValidationStrategy } = require("../src/");
14
15 //-----------------------------------------------------------------------------
16 // Class
17 //-----------------------------------------------------------------------------
18
19 describe("ValidationStrategy", () => {
20
21     describe("boolean", () => {
22         it("should not throw an error when the value is a boolean", () => {
23             ValidationStrategy.boolean(true);
24         });
25
26         it("should throw an error when the value is null", () => {
27             assert.throws(() => {
28                 ValidationStrategy.boolean(null);
29             }, /Expected a Boolean/);
30         });
31
32         it("should throw an error when the value is a string", () => {
33             assert.throws(() => {
34                 ValidationStrategy.boolean("foo");
35             }, /Expected a Boolean/);
36         });
37
38         it("should throw an error when the value is a number", () => {
39             assert.throws(() => {
40                 ValidationStrategy.boolean(123);
41             }, /Expected a Boolean/);
42         });
43
44         it("should throw an error when the value is an object", () => {
45             assert.throws(() => {
46                 ValidationStrategy.boolean({});
47             }, /Expected a Boolean/);
48         });
49     });
50
51     describe("number", () => {
52         it("should not throw an error when the value is a number", () => {
53             ValidationStrategy.number(25);
54         });
55
56         it("should throw an error when the value is null", () => {
57             assert.throws(() => {
58                 ValidationStrategy.number(null);
59             }, /Expected a number/);
60         });
61
62         it("should throw an error when the value is a string", () => {
63             assert.throws(() => {
64                 ValidationStrategy.number("foo");
65             }, /Expected a number/);
66         });
67
68         it("should throw an error when the value is a boolean", () => {
69             assert.throws(() => {
70                 ValidationStrategy.number(true);
71             }, /Expected a number/);
72         });
73
74         it("should throw an error when the value is an object", () => {
75             assert.throws(() => {
76                 ValidationStrategy.number({});
77             }, /Expected a number/);
78         });
79     });
80
81     describe("object", () => {
82         it("should not throw an error when the value is an object", () => {
83             ValidationStrategy.object({});
84         });
85
86         it("should throw an error when the value is null", () => {
87             assert.throws(() => {
88                 ValidationStrategy.object(null);
89             }, /Expected an object/);
90         });
91
92         it("should throw an error when the value is a string", () => {
93             assert.throws(() => {
94                 ValidationStrategy.object("");
95             }, /Expected an object/);
96         });
97     });
98
99     describe("array", () => {
100         it("should not throw an error when the value is an array", () => {
101             ValidationStrategy.array([]);
102         });
103
104         it("should throw an error when the value is null", () => {
105             assert.throws(() => {
106                 ValidationStrategy.array(null);
107             }, /Expected an array/);
108         });
109
110         it("should throw an error when the value is a string", () => {
111             assert.throws(() => {
112                 ValidationStrategy.array("");
113             }, /Expected an array/);
114         });
115
116         it("should throw an error when the value is an object", () => {
117             assert.throws(() => {
118                 ValidationStrategy.array({});
119             }, /Expected an array/);
120         });
121     });
122
123     describe("object?", () => {
124         it("should not throw an error when the value is an object", () => {
125             ValidationStrategy["object?"]({});
126         });
127
128         it("should not throw an error when the value is null", () => {
129             ValidationStrategy["object?"](null);
130         });
131
132         it("should throw an error when the value is a string", () => {
133             assert.throws(() => {
134                 ValidationStrategy["object?"]("");
135             }, /Expected an object/);
136         });
137     });
138
139     describe("string", () => {
140         it("should not throw an error when the value is a string", () => {
141             ValidationStrategy.string("foo");
142         });
143
144         it("should not throw an error when the value is an empty string", () => {
145             ValidationStrategy.string("");
146         });
147
148         it("should throw an error when the value is null", () => {
149             assert.throws(() => {
150                 ValidationStrategy.string(null);
151             }, /Expected a string/);
152         });
153
154         it("should throw an error when the value is an object", () => {
155             assert.throws(() => {
156                 ValidationStrategy.string({});
157             }, /Expected a string/);
158         });
159     });
160
161     describe("string!", () => {
162         it("should not throw an error when the value is an string", () => {
163             ValidationStrategy["string!"]("foo");
164         });
165
166         it("should throw an error when the value is an empty string", () => {
167             assert.throws(() => {
168                 ValidationStrategy["string!"]("");
169             }, /Expected a non-empty string/);
170         });
171
172         it("should throw an error when the value is null", () => {
173             assert.throws(() => {
174                 ValidationStrategy["string!"](null);
175             }, /Expected a non-empty string/);
176         });
177
178         it("should throw an error when the value is an object", () => {
179             assert.throws(() => {
180                 ValidationStrategy["string!"]({});
181             }, /Expected a non-empty string/);
182         });
183     });
184
185
186 });