I'm using ngx-formly (on V5) to generate a form with an input and a checkbox (here is the FormlyFieldConfig):
field: FormlyFieldConfig = {
className: 'database-header',
validators: {
validation: [
{ name: 'maxLengthIfExternal', options: { errorPath: 'name' } },
],
},
fieldGroup: [
{
className: 'align-left',
key: 'name',
type: 'input',
defaultValue: '',
templateOptions: {
required: true,
label: 'Database Name',
pattern: HYPHEN_REGEX_PATTERN_VALIDATION,
maxLength: 32,
},
validation: {
messages: {
pattern:
'Allowed characters: a-z 0-9 -, must start with lower case letter and end with an alphanumeric character',
},
},
},
{
key: 'external',
type: 'checkbox',
templateOptions: {
label:
'External',
},
},
],
};
I have a custom validator that is checking if the checkbox is checked (maxLengthIfExternal). If it is, the name input cannot be more than 8 characters.
I want to unit test (jest) the validation for this form: setting the input to more then 8 characters then clicking the checkbox and checking that the form is now invalid.
I can't find any documentation on how to unit test validation on formly. Does anyone know how to achieve that?