From f4121bf419b68b41780edb7d5777893132e9652d Mon Sep 17 00:00:00 2001 From: Jakob Scheid Date: Thu, 4 Jun 2026 14:38:05 +0200 Subject: [PATCH] test(settings): add unit test for the settings validator validateSelectionOptions function for test cases that should not throw an error --- .../settings/utils/__tests__/settingsValidator.test.js | 10 ++++++++-- src/features/settings/utils/settingsValidator.js | 4 ++-- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/features/settings/utils/__tests__/settingsValidator.test.js b/src/features/settings/utils/__tests__/settingsValidator.test.js index ff40170..ced00fd 100644 --- a/src/features/settings/utils/__tests__/settingsValidator.test.js +++ b/src/features/settings/utils/__tests__/settingsValidator.test.js @@ -15,7 +15,7 @@ limitations under the License. */ import { describe, test, expect } from 'vitest'; -import { assertType, assertString } from '../settingsValidator'; +import { validateSelectionOptions, assertType, assertString } from '../settingsValidator'; describe('validateSettingsConfig', () => { @@ -26,7 +26,13 @@ describe('validateEntry', () => { }); describe('validateSelectionOptions', () => { - + test.for([ + [[{ name: 'test', i18n: 'test.label' }]], + [[{ name: 'test', i18n: 'test.label' }, { name: 'test2', i18n: 'test2.label' }]], + [[{ name: 'test', i18n: 'test.label' }, { name: 'test', i18n: 'test2.label' }, { name: 'test3', i18n: 'test.label' }]] + ])('throws no error for the options %s', ([ options ]) => { + expect(() => validateSelectionOptions(options)).not.throws(Error); + }); }); describe('assertType', () => { diff --git a/src/features/settings/utils/settingsValidator.js b/src/features/settings/utils/settingsValidator.js index 7400c4c..a663a3a 100644 --- a/src/features/settings/utils/settingsValidator.js +++ b/src/features/settings/utils/settingsValidator.js @@ -30,10 +30,10 @@ export const assertType = function assertType (value, path) { } } -function validateSelectionOptions(options, path) { +export const validateSelectionOptions = function validateSelectionOptions (options, path) { if (!Array.isArray(options) || options.length === 0) { throw new Error(`[settings] "${path}.options" must be a non-empty array`); - } + }; options.forEach((opt, i) => { assertString(opt.name, `${path}.options[${i}].name`); assertString(opt.i18n, `${path}.options[${i}].i18n`);