custom function not called when schema has valid()
- Dominant language
- JavaScript
- Stars
- 21.2k
- Forks
- 1.5k
- Avg merge
- 4h 57m
- Merged PRs (30d)
- 14
Description
#### Context
* *node version*: 14.17.0
* *module version with issue*: 17.6.0
* *last module version without issue*: N/A
* *environment* (e.g. node, browser, native): node
* *used with* (e.g. hapi application, another framework, standalone, ...): node, and in testing with mocha
* *any other relevant information*:
#### What are you trying to achieve or the steps to reproduce?
I've been using custom methods to reformat (stringify) objects after validating them. Works great except when using .custom on a schema with valid() on it. When using them together, the custom function isn't called.
```typescript
it("should work with valid and custom", () => {
let customCalled = false
const schema = Joi.string().valid("baz")
.custom( (value, helper) => {
customCalled = true
return `foo-${value}`
})
const { value, warning, error } = schema.validate( "baz" )
customCalled.should.equal(true) // actual: false
expect(error).to.be.undefined
value.should.equal("foo-baz") // actual: baz
})
```
#### What was the result you got?
No custom method called, no value transformation.
#### What result did you expect?
I was hoping the custom method would be called after/if validation rules passed
Contributor guide
Assessment
This issue has not been assessed yet.