@@ -56,6 +56,21 @@ describe('parseToRgb', () => {
56
56
} )
57
57
} )
58
58
59
+ it ( 'should parse a rgba color representation with a precise alpha' , ( ) => {
60
+ expect ( parseToRgb ( 'rgba(174,67,255,.12345)' ) ) . toEqual ( {
61
+ alpha : 0.12345 ,
62
+ blue : 255 ,
63
+ green : 67 ,
64
+ red : 174 ,
65
+ } )
66
+ expect ( parseToRgb ( 'rgba(174,67,255,12.345%)' ) ) . toEqual ( {
67
+ alpha : 0.12345 ,
68
+ blue : 255 ,
69
+ green : 67 ,
70
+ red : 174 ,
71
+ } )
72
+ } )
73
+
59
74
it ( 'should parse a rgb color representation' , ( ) => {
60
75
expect ( parseToRgb ( 'rgb(174,67,255)' ) ) . toEqual ( {
61
76
blue : 255 ,
@@ -137,6 +152,21 @@ describe('parseToRgb', () => {
137
152
} )
138
153
} )
139
154
155
+ it ( 'should parse a hsla color representation with a precise alpha' , ( ) => {
156
+ expect ( parseToRgb ( 'hsla(210,10%,40%,.12345)' ) ) . toEqual ( {
157
+ alpha : 0.12345 ,
158
+ blue : 112 ,
159
+ green : 102 ,
160
+ red : 92 ,
161
+ } )
162
+ expect ( parseToRgb ( 'hsla(210,10%,40%,12.345%)' ) ) . toEqual ( {
163
+ alpha : 0.12345 ,
164
+ blue : 112 ,
165
+ green : 102 ,
166
+ red : 92 ,
167
+ } )
168
+ } )
169
+
140
170
it ( 'should throw an error if an invalid color string is provided' , ( ) => {
141
171
expect ( ( ) => {
142
172
parseToRgb ( '(174,67,255)' )
@@ -153,6 +183,38 @@ describe('parseToRgb', () => {
153
183
)
154
184
} )
155
185
186
+ it ( 'should throw an error if an invalid rgba string is provided' , ( ) => {
187
+ const colors = [
188
+ 'rgba(174,67,255,)' ,
189
+ 'rgba(174,67,255,%)' ,
190
+ 'rgba(174,67,255,.)' ,
191
+ 'rgba(174,67,255,1.)' ,
192
+ ]
193
+ colors . forEach ( color => {
194
+ expect ( ( ) => {
195
+ parseToRgb ( color )
196
+ } ) . toThrow (
197
+ "Couldn't parse the color string. Please provide the color as a string in hex, rgb, rgba, hsl or hsla notation." ,
198
+ )
199
+ } )
200
+ } )
201
+
202
+ it ( 'should throw an error if an invalid hsla string is provided' , ( ) => {
203
+ const colors = [
204
+ 'hsla(210,10%,40%,)' ,
205
+ 'hsla(210,10%,40%,%)' ,
206
+ 'hsla(210,10%,40%,.)' ,
207
+ 'hsla(210,10%,40%,1.)' ,
208
+ ]
209
+ colors . forEach ( color => {
210
+ expect ( ( ) => {
211
+ parseToRgb ( color )
212
+ } ) . toThrow (
213
+ "Couldn't parse the color string. Please provide the color as a string in hex, rgb, rgba, hsl or hsla notation." ,
214
+ )
215
+ } )
216
+ } )
217
+
156
218
it ( 'should throw an error if an invalid hsl string is provided' , ( ) => {
157
219
expect ( ( ) => {
158
220
parseToRgb ( 'hsl(210,120%,4%)' )
0 commit comments