Skip to content

Commit 9e14caa

Browse files
committed
Add missing numericality tests
1 parent 1b4da26 commit 9e14caa

File tree

1 file changed

+51
-1
lines changed

1 file changed

+51
-1
lines changed

packages/react-form-renderer/src/tests/validators/validators.test.js

Lines changed: 51 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { validators } from '../../constants';
2-
import { dataTypeValidator } from '../../validators/';
2+
import { dataTypeValidator, numericality } from '../../validators/';
33
import validatorMapper from '../../validators/validator-mapper';
44
import Validator from '../../validators/validators';
55
import messages from '../../validators/messages';
@@ -165,7 +165,57 @@ describe('New validators', () => {
165165
});
166166
});
167167

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+
168206
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+
169219
it('should return string validator and pass', () => {
170220
expect(dataTypeValidator('string')({ message: 'String message' })('Foo')).toBeUndefined();
171221
});

0 commit comments

Comments
 (0)