Consider numbers in the required validator#92
Consider numbers in the required validator#92v-borrego wants to merge 1 commit intoLemoncode:masterfrom
Conversation
|
|
||
| it('should return true if typeof value is number', () => { | ||
| // Arrange | ||
| const value = 1; |
There was a problem hiding this comment.
What is the validation if value is 0 or negative?
There was a problem hiding this comment.
Talking with @brauliodiez comments that we should not consider negative values, nor zero. That is, the validation fail in these cases:
- Value equals undefined
- Value equals null
- Value equals ' '
For another value, should pass validation:
- 'some text'
- 0
- 1
- -1
- {}
- []
- { property: 'value' }
etc.
@v-borrego, what do you think? Could you add some unit tests for these cases?
There was a problem hiding this comment.
Yes, I will add the tests in the next pull request
| return typeof value === 'string' ? | ||
| isStringValid(value, trim) : | ||
| value === true; | ||
| value === true || typeof value === "number"; |
There was a problem hiding this comment.
Extract value === true || typeof value === "number" in a function like isNonStringValid to check non string values. That is, is different than undefined or null
There was a problem hiding this comment.
Evaluate if value is different than null or undefined collides with the "When validating a non string value should return false if value is false" test. What do you consider for a boolean with false value?
The data model binded to the form may contain numerical attributes that are not being considered in the "required" validator