Skip to content

Array.includes() does not support more than 1 type #133

@runrightfast

Description

@runrightfast

Below is a test case that produces the issue. In other words, it only supports homogeneous arrays - not heterogeneous arrays. However, according to the docs, it should be able to support heterogeneous arrays.

describe.only('Joi Array Type', function() {
        it('can validate that its elements only include certain types', function() {
            var schema = {
                array : joi.types.Array().includes(joi.types.String().min(5), joi.types.Number().min(0))
            };

            var obj = {
                array : [ '12345' ]
            };
            var err = joi.validate(obj, schema);
            if (err) {
                throw new Error(JSON.stringify(obj) + '\n' + err);
            }

            obj = {
                array : [ '1234' ]
            };
            err = joi.validate(obj, schema);
            if (!err) {
                throw new Error(JSON.stringify(obj) + '\n Should be invalid because it contains a String with length < 5');
            }

            obj = {
                array : [ 3 ]
            };
            err = joi.validate(obj, schema);
            if (err) {
                throw new Error(JSON.stringify(obj) + '\n' + err);
            }

            obj = {
                array : [ '12345', 3 ]
            };
            err = joi.validate(obj, schema);
            if (err) {
                throw new Error(JSON.stringify(obj) + '\n' + err);
            }

        });

    });

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions