Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit622bf1b

Browse files
committed
fix: use throw and segregate the test cases
1 parentac30336 commit622bf1b

File tree

2 files changed

+17
-6
lines changed

2 files changed

+17
-6
lines changed

‎Conversions/RgbHslConversion.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@
1818
constcheckRgbFormat=(colorRgb)=>colorRgb.every(c=>c>=0&&c<=255);
1919

2020
constrgbToHsl=(colorRgb)=>{
21-
if(checkRgbFormat(colorRgb)===false){
22-
return'Input is not a valid RGB color.'
23-
}
21+
if(!checkRgbFormat(colorRgb)){
22+
thrownewError('Input is not a valid RGB color.');
23+
}
2424

2525
letcolorHsl=colorRgb
2626

‎Conversions/test/RgbHslConversion.test.js

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import{rgbToHsl}from'../RgbHslConversion'
22
describe('RgbHslConversion',()=>{
3-
consttestCases=[
3+
constvalidTestCases=[
44
[
55
[215,19,180],
66
[311,84,46]
@@ -28,16 +28,27 @@ describe('RgbHslConversion', () => {
2828
[
2929
[255,255,255],
3030
[0,0,100]
31-
],
31+
]
32+
]
33+
34+
consterrorTestCases=[
3235
[[256,180,9],'Input is not a valid RGB color.'],
3336
[[-90,46,8],'Input is not a valid RGB color.'],
3437
[[1,39,900],'Input is not a valid RGB color.']
3538
]
3639

37-
test.each(testCases)(
40+
41+
test.each(validTestCases)(
3842
'Should return the color in HSL format.',
3943
(colorRgb,expected)=>{
4044
expect(rgbToHsl(colorRgb)).toEqual(expected)
4145
}
4246
)
47+
48+
test.each(errorTestCases)(
49+
'Should return the error message.',
50+
(colorRgb,expected)=>{
51+
expect(()=>rgbToHsl(colorRgb)).toThrowError(expected)
52+
}
53+
)
4354
})

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp