joi
joi copied to clipboard
Custom validators recieve an unresolved promise when asynchronously validating.
Support plan
- is this issue currently blocking your project? (yes/no): no
- is this issue affecting a production system? (yes/no): no
Context
- node version: 15.7.0
- module version: 17.4.0
- environment (e.g. node, browser, native): node
- used with (e.g. hapi application, another framework, standalone, ...): custom framework
- any other relevant information:
How can we help?
const joi = require('joi');
joi
.string()
.custom((v) => v.slice(1))
.custom(
async (v) =>
await new Promise((res) => setTimeout(res, 10000, v.toUpperCase()))
)
.custom(
async (v) => await new Promise((res) => setTimeout(res, 10000, v, 'b'))
)
.validateAsync('foobar')
.then(console.log)
.catch(console.error);
The thrid custom validator recieves an unresolved promise (current workaround v=await v; ...
)
I'm unable to reproduce this issue in the specific context you've provided, can you please provide a sandbox link that can reproduce the issue please?
Here's the result of my reproduction runkit and it's working as expected: https://runkit.com/61a9b6de3e1f2500095245d5/61a9b6df317ba1000816b1d4