Joi.string() +.when() + .warning()
- Dominant language
- JavaScript
- Stars
- 21.2k
- Forks
- 1.5k
- Avg merge
- 4h 57m
- Merged PRs (30d)
- 14
Description
#### Support plan
* *is this issue currently blocking your project?* (yes/no): yes
* *is this issue affecting a production system?* (yes/no): yes
#### Context
* *node version*: 14.16.0
* *module version with issue*: 17.14.0
* *last module version without issue*: -
* *environment* (e.g. node, browser, native): node
* *used with* (e.g. hapi application, another framework, standalone, ...): standalone
* *any other relevant information*: -
#### What are you trying to achieve or the steps to reproduce?
The combination of Joi.string() + when + warning does not work, where it works with other types (only tested with any & number).
```js
{
const joiSchema = Joi.object({
prop1: Joi.string().required(),
prop2: Joi.string().when("prop1", {is: "warn", then: Joi.any().warning("Test warning", {})})
});
const {warning} = joiSchema.validate({prop1: "warn"});
console.log(warning); // undefined
}
{
const joiSchema = Joi.object({
prop1: Joi.number().required(),
prop2: Joi.string().when("prop1", {is: 1, then: Joi.any().warning("Test warning", {})})
});
const {warning} = joiSchema.validate({prop1: 1, prop2: "str"});
console.log(warning); // generates warning as expected
}
```
#### What was the result you got?
See above
#### What result did you expect?
See above
Contributor guide
Assessment
This issue has not been assessed yet.