Path: blob/1.0-develop/resources/scripts/lib/helpers.spec.ts
7458 views
import { hexToRgba } from '@/lib/helpers';12describe('@/lib/helpers.ts', function () {3describe('hexToRgba()', function () {4it('should return the expected rgba', function () {5expect(hexToRgba('#ffffff')).toBe('rgba(255, 255, 255, 1)');6expect(hexToRgba('#00aabb')).toBe('rgba(0, 170, 187, 1)');7expect(hexToRgba('#efefef')).toBe('rgba(239, 239, 239, 1)');8});910it('should ignore case', function () {11expect(hexToRgba('#FF00A3')).toBe('rgba(255, 0, 163, 1)');12});1314it('should allow alpha channel changes', function () {15expect(hexToRgba('#ece5a8', 0.5)).toBe('rgba(236, 229, 168, 0.5)');16expect(hexToRgba('#ece5a8', 0.1)).toBe('rgba(236, 229, 168, 0.1)');17expect(hexToRgba('#000000', 0)).toBe('rgba(0, 0, 0, 0)');18});1920it('should handle invalid strings', function () {21expect(hexToRgba('')).toBe('');22expect(hexToRgba('foobar')).toBe('foobar');23expect(hexToRgba('#fff')).toBe('#fff');24expect(hexToRgba('#')).toBe('#');25expect(hexToRgba('#fffffy')).toBe('#fffffy');26});27});28});293031