Skip to content

Schema

A schema is a set of rules for the tested object fields.

The rules can be defined in 3 different ways:

String

const schema = {
    firstname: 'required|min:3'
}

Array

const schema = {
    firstname: [
        'required',
        'min:3'
    ]
}

Function

const schema = {
    firstname: (value) => {
        if (value.length < 3) {
            return 'Firstname must be at least 3 characters long'
        }
        return true
    }
}