Content-Length: 3844 | pFad | http://github.com/TheAlgorithms/JavaScript/pull/1624.patch
thub.com
From 0f1e4e7d6d516b974879d328f505cd35d2c85851 Mon Sep 17 00:00:00 2001
From: Piotr Idzik
Date: Wed, 28 Feb 2024 21:08:54 +0000
Subject: [PATCH] fix: throw error instead of returning it
---
String/CheckFlatCase.js | 2 +-
String/CheckKebabCase.js | 2 +-
String/CheckPascalCase.js | 2 +-
String/test/CheckCamelCase.test.js | 4 ++++
String/test/CheckFlatCase.test.js | 4 ++++
String/test/CheckKebabCase.test.js | 4 ++++
String/test/CheckPascalCase.test.js | 4 ++++
7 files changed, 19 insertions(+), 3 deletions(-)
diff --git a/String/CheckFlatCase.js b/String/CheckFlatCase.js
index 709825edd1..5f8a332999 100644
--- a/String/CheckFlatCase.js
+++ b/String/CheckFlatCase.js
@@ -12,7 +12,7 @@
const checkFlatCase = (varname) => {
// firstly, check that input is a string or not.
if (typeof varname !== 'string') {
- return new TypeError('Argument is not a string.')
+ throw new TypeError('Argument is not a string.')
}
const pat = /^[a-z]*$/
diff --git a/String/CheckKebabCase.js b/String/CheckKebabCase.js
index 6e79ba6a5e..52d322f921 100644
--- a/String/CheckKebabCase.js
+++ b/String/CheckKebabCase.js
@@ -10,7 +10,7 @@
const CheckKebabCase = (varName) => {
// firstly, check that input is a string or not.
if (typeof varName !== 'string') {
- return new TypeError('Argument is not a string.')
+ throw new TypeError('Argument is not a string.')
}
const pat = /(\w+)-(\w)([\w-]*)/
diff --git a/String/CheckPascalCase.js b/String/CheckPascalCase.js
index 2e4c1ff3fa..71aaa26770 100644
--- a/String/CheckPascalCase.js
+++ b/String/CheckPascalCase.js
@@ -10,7 +10,7 @@
const CheckPascalCase = (VarName) => {
// firstly, check that input is a string or not.
if (typeof VarName !== 'string') {
- return new TypeError('Argument is not a string.')
+ throw new TypeError('Argument is not a string.')
}
const pat = /^[A-Z][A-Za-z]*$/
diff --git a/String/test/CheckCamelCase.test.js b/String/test/CheckCamelCase.test.js
index c1e2d83005..5875e0cd10 100644
--- a/String/test/CheckCamelCase.test.js
+++ b/String/test/CheckCamelCase.test.js
@@ -15,4 +15,8 @@ describe('checkCamelCase', () => {
const result = checkCamelCase(value)
expect(result).toBe(false)
})
+
+ it('should throw when input is not a string', () => {
+ expect(() => checkCamelCase(100)).toThrowError()
+ })
})
diff --git a/String/test/CheckFlatCase.test.js b/String/test/CheckFlatCase.test.js
index 0277f7c0e1..ccac811bf6 100644
--- a/String/test/CheckFlatCase.test.js
+++ b/String/test/CheckFlatCase.test.js
@@ -15,4 +15,8 @@ describe('checkFlatCase function', () => {
const actual = checkFlatCase('abcdefghijklmnopqrstuvwxyz')
expect(actual).toBe(true)
})
+
+ it('should throw when input is not a string', () => {
+ expect(() => checkFlatCase(100)).toThrowError()
+ })
})
diff --git a/String/test/CheckKebabCase.test.js b/String/test/CheckKebabCase.test.js
index 45bc5f2d52..239d91674e 100644
--- a/String/test/CheckKebabCase.test.js
+++ b/String/test/CheckKebabCase.test.js
@@ -11,3 +11,7 @@ test('CheckKebabCase(The Algorithms) -> false', () => {
const res = CheckKebabCase(word)
expect(res).toBeFalsy()
})
+
+test('CheckKebabCase throws when input is not a string', () => {
+ expect(() => CheckKebabCase(100)).toThrowError()
+})
diff --git a/String/test/CheckPascalCase.test.js b/String/test/CheckPascalCase.test.js
index 2587023f79..139b66844b 100644
--- a/String/test/CheckPascalCase.test.js
+++ b/String/test/CheckPascalCase.test.js
@@ -17,3 +17,7 @@ test('CheckPascalCase(The Algorithms) -> false', () => {
const res = CheckPascalCase(word)
expect(res).toBeFalsy()
})
+
+test('CheckPascalCase throws when input is not a string', () => {
+ expect(() => CheckPascalCase(100)).toThrowError()
+})
--- a PPN by Garber Painting Akron. With Image Size Reduction included!Fetched URL: http://github.com/TheAlgorithms/JavaScript/pull/1624.patch
Alternative Proxies:
Alternative Proxy
pFad Proxy
pFad v3 Proxy
pFad v4 Proxy