Skip to content

Yup Custom Validation (addMethod) Bug #163

@sanzhardanybayev

Description

@sanzhardanybayev

Describe the bug
Code breaks when adding custom validation logic via addMethod function.

Code returns :
vendors-node_modules_apollo_client_index_js-node_modules_hookform_resolvers_yup_dist_yup_modu-7f163c.js:9521 Uncaught (in promise) TypeError: Cannot read property 'reduce' of undefined message.

To Reproduce
Just add custom validation to yup

yup.addMethod(yup.object, 'localeEqual', function (errorMessage) {
    return this.test('locale-equal', errorMessage, function (value) {
        const {path, createError} = this
        return value.kz.length === value.ru.length || createError({path, message: errorMessage})
    })
})

CodeSandbox
https://codesandbox.io/s/yup-custom-validation-error-41x1n?file=/src/App.js

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions