|
1 | 1 | import { validators } from '../../constants';
|
2 |
| -import { dataTypeValidator } from '../../validators/'; |
| 2 | +import { dataTypeValidator, numericality } from '../../validators/'; |
3 | 3 | import validatorMapper from '../../validators/validator-mapper';
|
4 | 4 | import Validator from '../../validators/validators';
|
5 | 5 | import messages from '../../validators/messages';
|
@@ -165,7 +165,57 @@ describe('New validators', () => {
|
165 | 165 | });
|
166 | 166 | });
|
167 | 167 |
|
| 168 | + describe('numericality validators', () => { |
| 169 | + it('is not number', () => { |
| 170 | + expect(numericality({ equal: 5 })('string')).toEqual('Value is not a number'); |
| 171 | + }); |
| 172 | + |
| 173 | + it('is not equal', () => { |
| 174 | + expect(numericality({ '=': 5 })(6)).toEqual('must be equal to 5.'); |
| 175 | + }); |
| 176 | + |
| 177 | + it('is not different', () => { |
| 178 | + expect(numericality({ '!=': 5 })(5)).toEqual('Value must be other than 5.'); |
| 179 | + }); |
| 180 | + |
| 181 | + it('is not goe', () => { |
| 182 | + expect(numericality({ '>=': 5 })(4)).toEqual('Value must be greater than or equal to 5.'); |
| 183 | + }); |
| 184 | + |
| 185 | + it('is not loe', () => { |
| 186 | + expect(numericality({ '<=': 5 })(6)).toEqual('Value must be less than or equal to 5'); |
| 187 | + }); |
| 188 | + |
| 189 | + it('is not greater', () => { |
| 190 | + expect(numericality({ '>': 5 })(5)).toEqual('Value must be greater than 5.'); |
| 191 | + }); |
| 192 | + |
| 193 | + it('is not less', () => { |
| 194 | + expect(numericality({ '<': 5 })(5)).toEqual('Value must be less than 5'); |
| 195 | + }); |
| 196 | + |
| 197 | + it('is not even', () => { |
| 198 | + expect(numericality({ even: true })(5)).toEqual('Number must be even'); |
| 199 | + }); |
| 200 | + |
| 201 | + it('is not odd', () => { |
| 202 | + expect(numericality({ odd: true })(4)).toEqual('Number must be odd'); |
| 203 | + }); |
| 204 | + }); |
| 205 | + |
168 | 206 | describe('data type validator', () => {
|
| 207 | + it('should return float and pass', () => { |
| 208 | + expect(dataTypeValidator('float')()(123.232)).toBeUndefined(); |
| 209 | + }); |
| 210 | + |
| 211 | + it('should return float and pass 2', () => { |
| 212 | + expect(dataTypeValidator('float')()(123)).toBeUndefined(); |
| 213 | + }); |
| 214 | + |
| 215 | + it('should return float validator and fail', () => { |
| 216 | + expect(dataTypeValidator('float')({ message: 'Should be float' })('string')).toEqual('Should be float'); |
| 217 | + }); |
| 218 | + |
169 | 219 | it('should return string validator and pass', () => {
|
170 | 220 | expect(dataTypeValidator('string')({ message: 'String message' })('Foo')).toBeUndefined();
|
171 | 221 | });
|
|
0 commit comments