|
| 1 | +import { hex2rgba } from './hex2rgba' |
| 2 | + |
| 3 | +describe('hex2rgba', () => { |
| 4 | + // Test wrong hex code |
| 5 | + it('should handle wrong hex code - 1', () => { |
| 6 | + const hex = '#test' |
| 7 | + const expected = 'rgba(0, 0, 0, 0.75)' |
| 8 | + const result = hex2rgba(hex) |
| 9 | + expect(result).toEqual(expected) |
| 10 | + }) |
| 11 | + |
| 12 | + it('should handle wrong hex code - 2', () => { |
| 13 | + const hex = 'test' |
| 14 | + const expected = 'rgba(0, 0, 0, 0.75)' |
| 15 | + const result = hex2rgba(hex) |
| 16 | + expect(result).toEqual(expected) |
| 17 | + }) |
| 18 | + |
| 19 | + it('should handle wrong hex code - 3', () => { |
| 20 | + const hex = '#<32' |
| 21 | + const expected = 'rgba(0, 0, 0, 0.75)' |
| 22 | + const result = hex2rgba(hex) |
| 23 | + expect(result).toEqual(expected) |
| 24 | + }) |
| 25 | + |
| 26 | + // Check if function correctly converts hex code to rgba |
| 27 | + it('should convert a 3-digit hex code to rgba format', () => { |
| 28 | + const hex = '#abc' |
| 29 | + const expected = 'rgba(170,187,204,0.75)' |
| 30 | + const result = hex2rgba(hex) |
| 31 | + expect(result).toEqual(expected) |
| 32 | + }) |
| 33 | + |
| 34 | + it('should convert a 6-digit hex code to rgba format', () => { |
| 35 | + const hex = '#abcdef' |
| 36 | + const expected = 'rgba(171,205,239,0.75)' |
| 37 | + const result = hex2rgba(hex) |
| 38 | + expect(result).toEqual(expected) |
| 39 | + }) |
| 40 | + |
| 41 | + it('should convert a 3-digit hex code with custom alpha value to rgba format', () => { |
| 42 | + const hex = '#abc' |
| 43 | + const alpha = 0.5 |
| 44 | + const expected = 'rgba(170,187,204,0.5)' |
| 45 | + const result = hex2rgba(hex, alpha) |
| 46 | + expect(result).toEqual(expected) |
| 47 | + }) |
| 48 | + |
| 49 | + it('should convert a 6-digit hex code with custom alpha value to rgba format', () => { |
| 50 | + const hex = '#abcdef' |
| 51 | + const alpha = 0.25 |
| 52 | + const expected = 'rgba(171,205,239,0.25)' |
| 53 | + const result = hex2rgba(hex, alpha) |
| 54 | + expect(result).toEqual(expected) |
| 55 | + }) |
| 56 | +}) |
0 commit comments