generated from Seekra/repository-template
Add settings validator unit test #113
@@ -15,7 +15,7 @@ limitations under the License.
|
||||
*/
|
||||
|
||||
import { describe, test, expect } from 'vitest';
|
||||
import { assertString } from '../settingsValidator';
|
||||
import { assertType, assertString } from '../settingsValidator';
|
||||
|
||||
describe('validateSettingsConfig', () => {
|
||||
|
||||
@@ -30,7 +30,15 @@ describe('validateSelectionOptions', () => {
|
||||
});
|
||||
|
||||
describe('assertType', () => {
|
||||
|
||||
test.for([
|
||||
['bool'],
|
||||
['number'],
|
||||
['string'],
|
||||
['selection'],
|
||||
['section']
|
||||
])('throws no error for the value %s', ([ value ]) => {
|
||||
expect(() => assertType(value)).not.throw(Error);
|
||||
});
|
||||
});
|
||||
|
||||
describe('assertString', () => {
|
||||
|
||||
@@ -22,7 +22,7 @@ export const assertString = function assertString (value, path) {
|
||||
}
|
||||
}
|
||||
|
||||
function assertType(value, path) {
|
||||
export const assertType = function assertType (value, path) {
|
||||
if (!VALID_TYPES.includes(value)) {
|
||||
throw new Error(
|
||||
`[settings] "${path}" has invalid type "${value}". Must be one of: ${VALID_TYPES.join(', ')}`
|
||||
|
||||
Reference in New Issue
Block a user