|
1 | 1 | import { offsetMin, offsetMax } from 'utils/propValidation';
|
2 | 2 |
|
3 | 3 | describe('offsetMin prop validation', () => {
|
4 |
| - |
5 | 4 | it('returns null when provided a valid value', () => {
|
6 | 5 | expect(offsetMin({ offsetXMin: -100 }, 'offsetXMin', 'foo')).toBe(null);
|
7 |
| - expect(offsetMin({ offsetXMin: '-10321px' }, 'offsetXMin', 'foo')).toBe(null); |
8 |
| - expect(offsetMin({ offsetXMin: '-10%' }, 'offsetXMin', 'foo')).toBe(null); |
| 6 | + expect(offsetMin({ offsetXMin: '-10321px' }, 'offsetXMin', 'foo')).toBe( |
| 7 | + null |
| 8 | + ); |
| 9 | + expect(offsetMin({ offsetXMin: '-10%' }, 'offsetXMin', 'foo')).toBe( |
| 10 | + null |
| 11 | + ); |
9 | 12 | });
|
10 | 13 |
|
11 | 14 | it('throws when provided a invalid value type', () => {
|
12 |
| - const error = new Error('[offsetXMin] in foo must be a string with with "%"" or "px" units or number.'); |
13 |
| - expect(offsetMin({ offsetXMin: false }, 'offsetXMin', 'foo')).toEqual(error); |
14 |
| - expect(offsetMin({ offsetXMin: {} }, 'offsetXMin', 'foo')).toEqual(error); |
15 |
| - expect(offsetMin({ offsetXMin: null }, 'offsetXMin', 'foo')).toEqual(error); |
16 |
| - expect(offsetMin({ offsetXMin: undefined }, 'offsetXMin', 'foo')).toEqual(error); |
17 |
| - expect(offsetMin({ offsetXMin: [] }, 'offsetXMin', 'foo')).toEqual(error); |
| 15 | + const error = new Error( |
| 16 | + '[offsetXMin] in foo must be a string with with "%"" or "px" units or number.' |
| 17 | + ); |
| 18 | + expect(offsetMin({ offsetXMin: false }, 'offsetXMin', 'foo')).toEqual( |
| 19 | + error |
| 20 | + ); |
| 21 | + expect(offsetMin({ offsetXMin: {} }, 'offsetXMin', 'foo')).toEqual( |
| 22 | + error |
| 23 | + ); |
| 24 | + expect(offsetMin({ offsetXMin: null }, 'offsetXMin', 'foo')).toEqual( |
| 25 | + error |
| 26 | + ); |
| 27 | + expect( |
| 28 | + offsetMin({ offsetXMin: undefined }, 'offsetXMin', 'foo') |
| 29 | + ).toEqual(error); |
| 30 | + expect(offsetMin({ offsetXMin: [] }, 'offsetXMin', 'foo')).toEqual( |
| 31 | + error |
| 32 | + ); |
18 | 33 | });
|
19 | 34 |
|
20 | 35 | it('throws when provided a invalid value', () => {
|
21 |
| - const error = new Error('[offsetXMin] in foo is greater than zero. [offsetXMin] must be less than or equal to zero.') |
22 |
| - expect(offsetMin({ offsetXMin: 100 }, 'offsetXMin', 'foo')).toEqual(error); |
23 |
| - expect(offsetMin({ offsetXMin: 1 }, 'offsetXMin', 'foo')).toEqual(error); |
24 |
| - expect(offsetMin({ offsetXMin: 0.0009 }, 'offsetXMin', 'foo')).toEqual(error); |
25 |
| - expect(offsetMin({ offsetXMin: '100px' }, 'offsetXMin', 'foo')).toEqual(error); |
26 |
| - expect(offsetMin({ offsetXMin: '99%' }, 'offsetXMin', 'foo')).toEqual(error); |
| 36 | + const error = new Error( |
| 37 | + '[offsetXMin] in foo is greater than zero. [offsetXMin] must be less than or equal to zero.' |
| 38 | + ); |
| 39 | + expect(offsetMin({ offsetXMin: 100 }, 'offsetXMin', 'foo')).toEqual( |
| 40 | + error |
| 41 | + ); |
| 42 | + expect(offsetMin({ offsetXMin: 1 }, 'offsetXMin', 'foo')).toEqual( |
| 43 | + error |
| 44 | + ); |
| 45 | + expect(offsetMin({ offsetXMin: 0.0009 }, 'offsetXMin', 'foo')).toEqual( |
| 46 | + error |
| 47 | + ); |
| 48 | + expect(offsetMin({ offsetXMin: '100px' }, 'offsetXMin', 'foo')).toEqual( |
| 49 | + error |
| 50 | + ); |
| 51 | + expect(offsetMin({ offsetXMin: '99%' }, 'offsetXMin', 'foo')).toEqual( |
| 52 | + error |
| 53 | + ); |
27 | 54 | });
|
28 |
| - |
29 | 55 | });
|
30 | 56 |
|
31 | 57 | describe('offsetMax prop validation', () => {
|
32 |
| - |
33 | 58 | it('returns null when provided a valid value', () => {
|
34 | 59 | expect(offsetMax({ offsetXMax: 100 }, 'offsetXMax', 'foo')).toBe(null);
|
35 |
| - expect(offsetMax({ offsetXMax: '10321px' }, 'offsetXMax', 'foo')).toBe(null); |
36 |
| - expect(offsetMax({ offsetXMax: '10%' }, 'offsetXMax', 'foo')).toBe(null); |
| 60 | + expect(offsetMax({ offsetXMax: '10321px' }, 'offsetXMax', 'foo')).toBe( |
| 61 | + null |
| 62 | + ); |
| 63 | + expect(offsetMax({ offsetXMax: '10%' }, 'offsetXMax', 'foo')).toBe( |
| 64 | + null |
| 65 | + ); |
37 | 66 | });
|
38 | 67 |
|
39 | 68 | it('throws when provided a invalid value type', () => {
|
40 |
| - const error = new Error('[offsetXMax] in foo must be a string with with "%"" or "px" units or number.'); |
41 |
| - expect(offsetMax({ offsetXMax: false }, 'offsetXMax', 'foo')).toEqual(error); |
42 |
| - expect(offsetMax({ offsetXMax: {} }, 'offsetXMax', 'foo')).toEqual(error); |
43 |
| - expect(offsetMax({ offsetXMax: null }, 'offsetXMax', 'foo')).toEqual(error); |
44 |
| - expect(offsetMax({ offsetXMax: undefined }, 'offsetXMax', 'foo')).toEqual(error); |
45 |
| - expect(offsetMax({ offsetXMax: [] }, 'offsetXMax', 'foo')).toEqual(error); |
| 69 | + const error = new Error( |
| 70 | + '[offsetXMax] in foo must be a string with with "%"" or "px" units or number.' |
| 71 | + ); |
| 72 | + expect(offsetMax({ offsetXMax: false }, 'offsetXMax', 'foo')).toEqual( |
| 73 | + error |
| 74 | + ); |
| 75 | + expect(offsetMax({ offsetXMax: {} }, 'offsetXMax', 'foo')).toEqual( |
| 76 | + error |
| 77 | + ); |
| 78 | + expect(offsetMax({ offsetXMax: null }, 'offsetXMax', 'foo')).toEqual( |
| 79 | + error |
| 80 | + ); |
| 81 | + expect( |
| 82 | + offsetMax({ offsetXMax: undefined }, 'offsetXMax', 'foo') |
| 83 | + ).toEqual(error); |
| 84 | + expect(offsetMax({ offsetXMax: [] }, 'offsetXMax', 'foo')).toEqual( |
| 85 | + error |
| 86 | + ); |
46 | 87 | });
|
47 | 88 |
|
48 | 89 | it('throws when provided a invalid value', () => {
|
49 |
| - const error = new Error('[offsetXMax] in foo is less than zero. [offsetXMax] must be greater than or equal to zero.') |
50 |
| - expect(offsetMax({ offsetXMax: -100 }, 'offsetXMax', 'foo')).toEqual(error); |
51 |
| - expect(offsetMax({ offsetXMax: -1 }, 'offsetXMax', 'foo')).toEqual(error); |
52 |
| - expect(offsetMax({ offsetXMax: -0.0009 }, 'offsetXMax', 'foo')).toEqual(error); |
53 |
| - expect(offsetMax({ offsetXMax: '-100px' }, 'offsetXMax', 'foo')).toEqual(error); |
54 |
| - expect(offsetMax({ offsetXMax: '-99%' }, 'offsetXMax', 'foo')).toEqual(error); |
| 90 | + const error = new Error( |
| 91 | + '[offsetXMax] in foo is less than zero. [offsetXMax] must be greater than or equal to zero.' |
| 92 | + ); |
| 93 | + expect(offsetMax({ offsetXMax: -100 }, 'offsetXMax', 'foo')).toEqual( |
| 94 | + error |
| 95 | + ); |
| 96 | + expect(offsetMax({ offsetXMax: -1 }, 'offsetXMax', 'foo')).toEqual( |
| 97 | + error |
| 98 | + ); |
| 99 | + expect(offsetMax({ offsetXMax: -0.0009 }, 'offsetXMax', 'foo')).toEqual( |
| 100 | + error |
| 101 | + ); |
| 102 | + expect( |
| 103 | + offsetMax({ offsetXMax: '-100px' }, 'offsetXMax', 'foo') |
| 104 | + ).toEqual(error); |
| 105 | + expect(offsetMax({ offsetXMax: '-99%' }, 'offsetXMax', 'foo')).toEqual( |
| 106 | + error |
| 107 | + ); |
55 | 108 | });
|
56 |
| - |
57 | 109 | });
|
0 commit comments