|
| 1 | +import matchPercent from './matchPercent'; |
| 2 | + |
| 3 | +describe('match percent', () => { |
| 4 | + test('should return null for null input', () => { |
| 5 | + expect(matchPercent(null)).toBeNull(); |
| 6 | + }); |
| 7 | + |
| 8 | + test('should return null for numeric inputs', () => { |
| 9 | + expect(matchPercent(40)).toBeNull(); |
| 10 | + }); |
| 11 | + |
| 12 | + test('should return null for wrong string inputs', () => { |
| 13 | + expect(matchPercent('hey%')).toBeNull(); |
| 14 | + }); |
| 15 | + |
| 16 | + test('should return value for positive integer percents', () => { |
| 17 | + const match = matchPercent('35%'); |
| 18 | + |
| 19 | + expect(match.value).toBe(35); |
| 20 | + expect(match.percent).toBe(0.35); |
| 21 | + }); |
| 22 | + |
| 23 | + test('should return value for positive real percents', () => { |
| 24 | + const match = matchPercent('35.5%'); |
| 25 | + |
| 26 | + expect(match.value).toBe(35.5); |
| 27 | + expect(match.percent).toBe(0.355); |
| 28 | + }); |
| 29 | + |
| 30 | + test('should return value for negative integer percents', () => { |
| 31 | + const match = matchPercent('-35%'); |
| 32 | + |
| 33 | + expect(match.value).toBe(-35); |
| 34 | + expect(match.percent).toBe(-0.35); |
| 35 | + }); |
| 36 | + |
| 37 | + test('should return value for negative real percents', () => { |
| 38 | + const match = matchPercent('-35.5%'); |
| 39 | + |
| 40 | + expect(match.value).toBe(-35.5); |
| 41 | + expect(match.percent).toBe(-0.355); |
| 42 | + }); |
| 43 | +}); |
0 commit comments