From 156b3b552c3d3366e9fd695ad88269565602b2e4 Mon Sep 17 00:00:00 2001 From: Jakob Scheid Date: Thu, 4 Jun 2026 13:53:47 +0200 Subject: [PATCH] test(settings): add unit test for the settings validator assertString function for test cases that should throw an error --- .../utils/__tests__/settingsValidator.test.js | 16 +++++++++++++++- src/features/settings/utils/settingsValidator.js | 2 +- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/src/features/settings/utils/__tests__/settingsValidator.test.js b/src/features/settings/utils/__tests__/settingsValidator.test.js index 923f4d9..2d54b20 100644 --- a/src/features/settings/utils/__tests__/settingsValidator.test.js +++ b/src/features/settings/utils/__tests__/settingsValidator.test.js @@ -14,7 +14,8 @@ See the License for the specific language governing permissions and limitations under the License. */ -import { describe } from 'vitest'; +import { describe, test, expect } from 'vitest'; +import { assertString } from '../settingsValidator'; describe('validateSettingsConfig', () => { @@ -33,5 +34,18 @@ describe('assertType', () => { }); describe('assertString', () => { + test.for([ + [0], + [1], + [42], + [-1], + [-42], + [''], + [' '], + [' '], + [' '] + ])('throws error for the value %s', ([ value ]) => { + expect(() => assertString(value)).throws(Error); + }); }); \ No newline at end of file diff --git a/src/features/settings/utils/settingsValidator.js b/src/features/settings/utils/settingsValidator.js index ec30713..74372be 100644 --- a/src/features/settings/utils/settingsValidator.js +++ b/src/features/settings/utils/settingsValidator.js @@ -16,7 +16,7 @@ limitations under the License. const VALID_TYPES = ['bool', 'number', 'string', 'selection', 'section']; -function assertString(value, path) { +export const assertString = function assertString (value, path) { if (typeof value !== 'string' || value.trim() === '') { throw new Error(`[settings] "${path}" must be a non-empty string`); }