2 * @filedescription Merge Strategy Tests
4 /* global it, describe, beforeEach */
8 //-----------------------------------------------------------------------------
10 //-----------------------------------------------------------------------------
12 const assert = require("chai").assert;
13 const { ValidationStrategy } = require("../src/");
15 //-----------------------------------------------------------------------------
17 //-----------------------------------------------------------------------------
19 describe("ValidationStrategy", () => {
21 describe("boolean", () => {
22 it("should not throw an error when the value is a boolean", () => {
23 ValidationStrategy.boolean(true);
26 it("should throw an error when the value is null", () => {
28 ValidationStrategy.boolean(null);
29 }, /Expected a Boolean/);
32 it("should throw an error when the value is a string", () => {
34 ValidationStrategy.boolean("foo");
35 }, /Expected a Boolean/);
38 it("should throw an error when the value is a number", () => {
40 ValidationStrategy.boolean(123);
41 }, /Expected a Boolean/);
44 it("should throw an error when the value is an object", () => {
46 ValidationStrategy.boolean({});
47 }, /Expected a Boolean/);
51 describe("number", () => {
52 it("should not throw an error when the value is a number", () => {
53 ValidationStrategy.number(25);
56 it("should throw an error when the value is null", () => {
58 ValidationStrategy.number(null);
59 }, /Expected a number/);
62 it("should throw an error when the value is a string", () => {
64 ValidationStrategy.number("foo");
65 }, /Expected a number/);
68 it("should throw an error when the value is a boolean", () => {
70 ValidationStrategy.number(true);
71 }, /Expected a number/);
74 it("should throw an error when the value is an object", () => {
76 ValidationStrategy.number({});
77 }, /Expected a number/);
81 describe("object", () => {
82 it("should not throw an error when the value is an object", () => {
83 ValidationStrategy.object({});
86 it("should throw an error when the value is null", () => {
88 ValidationStrategy.object(null);
89 }, /Expected an object/);
92 it("should throw an error when the value is a string", () => {
94 ValidationStrategy.object("");
95 }, /Expected an object/);
99 describe("array", () => {
100 it("should not throw an error when the value is an array", () => {
101 ValidationStrategy.array([]);
104 it("should throw an error when the value is null", () => {
105 assert.throws(() => {
106 ValidationStrategy.array(null);
107 }, /Expected an array/);
110 it("should throw an error when the value is a string", () => {
111 assert.throws(() => {
112 ValidationStrategy.array("");
113 }, /Expected an array/);
116 it("should throw an error when the value is an object", () => {
117 assert.throws(() => {
118 ValidationStrategy.array({});
119 }, /Expected an array/);
123 describe("object?", () => {
124 it("should not throw an error when the value is an object", () => {
125 ValidationStrategy["object?"]({});
128 it("should not throw an error when the value is null", () => {
129 ValidationStrategy["object?"](null);
132 it("should throw an error when the value is a string", () => {
133 assert.throws(() => {
134 ValidationStrategy["object?"]("");
135 }, /Expected an object/);
139 describe("string", () => {
140 it("should not throw an error when the value is a string", () => {
141 ValidationStrategy.string("foo");
144 it("should not throw an error when the value is an empty string", () => {
145 ValidationStrategy.string("");
148 it("should throw an error when the value is null", () => {
149 assert.throws(() => {
150 ValidationStrategy.string(null);
151 }, /Expected a string/);
154 it("should throw an error when the value is an object", () => {
155 assert.throws(() => {
156 ValidationStrategy.string({});
157 }, /Expected a string/);
161 describe("string!", () => {
162 it("should not throw an error when the value is an string", () => {
163 ValidationStrategy["string!"]("foo");
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/);
172 it("should throw an error when the value is null", () => {
173 assert.throws(() => {
174 ValidationStrategy["string!"](null);
175 }, /Expected a non-empty string/);
178 it("should throw an error when the value is an object", () => {
179 assert.throws(() => {
180 ValidationStrategy["string!"]({});
181 }, /Expected a non-empty string/);