HEX
Server: Apache/2.4.41 (Ubuntu)
System: Linux wordpress-ubuntu-s-2vcpu-4gb-fra1-01 5.4.0-169-generic #187-Ubuntu SMP Thu Nov 23 14:52:28 UTC 2023 x86_64
User: root (0)
PHP: 7.4.33
Disabled: pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare,
Upload Files
File: /var/www/linde-ai/html/node_modules/@humanwhocodes/object-schema/tests/validation-strategy.js
/**
 * @filedescription Merge Strategy Tests
 */
/* global it, describe, beforeEach */

"use strict";

//-----------------------------------------------------------------------------
// Requirements
//-----------------------------------------------------------------------------

const assert = require("chai").assert;
const { ValidationStrategy } = require("../src/");

//-----------------------------------------------------------------------------
// Class
//-----------------------------------------------------------------------------

describe("ValidationStrategy", () => {

    describe("boolean", () => {
        it("should not throw an error when the value is a boolean", () => {
            ValidationStrategy.boolean(true);
        });

        it("should throw an error when the value is null", () => {
            assert.throws(() => {
                ValidationStrategy.boolean(null);
            }, /Expected a Boolean/);
        });

        it("should throw an error when the value is a string", () => {
            assert.throws(() => {
                ValidationStrategy.boolean("foo");
            }, /Expected a Boolean/);
        });

        it("should throw an error when the value is a number", () => {
            assert.throws(() => {
                ValidationStrategy.boolean(123);
            }, /Expected a Boolean/);
        });

        it("should throw an error when the value is an object", () => {
            assert.throws(() => {
                ValidationStrategy.boolean({});
            }, /Expected a Boolean/);
        });
    });

    describe("number", () => {
        it("should not throw an error when the value is a number", () => {
            ValidationStrategy.number(25);
        });

        it("should throw an error when the value is null", () => {
            assert.throws(() => {
                ValidationStrategy.number(null);
            }, /Expected a number/);
        });

        it("should throw an error when the value is a string", () => {
            assert.throws(() => {
                ValidationStrategy.number("foo");
            }, /Expected a number/);
        });

        it("should throw an error when the value is a boolean", () => {
            assert.throws(() => {
                ValidationStrategy.number(true);
            }, /Expected a number/);
        });

        it("should throw an error when the value is an object", () => {
            assert.throws(() => {
                ValidationStrategy.number({});
            }, /Expected a number/);
        });
    });

    describe("object", () => {
        it("should not throw an error when the value is an object", () => {
            ValidationStrategy.object({});
        });

        it("should throw an error when the value is null", () => {
            assert.throws(() => {
                ValidationStrategy.object(null);
            }, /Expected an object/);
        });

        it("should throw an error when the value is a string", () => {
            assert.throws(() => {
                ValidationStrategy.object("");
            }, /Expected an object/);
        });
    });

    describe("array", () => {
        it("should not throw an error when the value is an array", () => {
            ValidationStrategy.array([]);
        });

        it("should throw an error when the value is null", () => {
            assert.throws(() => {
                ValidationStrategy.array(null);
            }, /Expected an array/);
        });

        it("should throw an error when the value is a string", () => {
            assert.throws(() => {
                ValidationStrategy.array("");
            }, /Expected an array/);
        });

        it("should throw an error when the value is an object", () => {
            assert.throws(() => {
                ValidationStrategy.array({});
            }, /Expected an array/);
        });
    });

    describe("object?", () => {
        it("should not throw an error when the value is an object", () => {
            ValidationStrategy["object?"]({});
        });

        it("should not throw an error when the value is null", () => {
            ValidationStrategy["object?"](null);
        });

        it("should throw an error when the value is a string", () => {
            assert.throws(() => {
                ValidationStrategy["object?"]("");
            }, /Expected an object/);
        });
    });

    describe("string", () => {
        it("should not throw an error when the value is a string", () => {
            ValidationStrategy.string("foo");
        });

        it("should not throw an error when the value is an empty string", () => {
            ValidationStrategy.string("");
        });

        it("should throw an error when the value is null", () => {
            assert.throws(() => {
                ValidationStrategy.string(null);
            }, /Expected a string/);
        });

        it("should throw an error when the value is an object", () => {
            assert.throws(() => {
                ValidationStrategy.string({});
            }, /Expected a string/);
        });
    });

    describe("string!", () => {
        it("should not throw an error when the value is an string", () => {
            ValidationStrategy["string!"]("foo");
        });

        it("should throw an error when the value is an empty string", () => {
            assert.throws(() => {
                ValidationStrategy["string!"]("");
            }, /Expected a non-empty string/);
        });

        it("should throw an error when the value is null", () => {
            assert.throws(() => {
                ValidationStrategy["string!"](null);
            }, /Expected a non-empty string/);
        });

        it("should throw an error when the value is an object", () => {
            assert.throws(() => {
                ValidationStrategy["string!"]({});
            }, /Expected a non-empty string/);
        });
    });


});