This commit is contained in:
2025-09-12 10:33:16 +02:00
parent 0f0edda91a
commit e397c5217a
2 changed files with 15 additions and 14 deletions
+2 -1
View File
@@ -44,7 +44,8 @@ export async function object<S extends yup.Maybe<yup.AnyObject>>(
}
} else {
// Normal handling of value (for arrays, split by ',')
const less_raw = type === 'array' ? (raw.data.length === 0 ? [] : raw.data.split(',')) : raw.data
const less_raw =
type === 'array' || type === 'tuple' ? (raw.data.length === 0 ? [] : raw.data.split(',')) : raw.data
value = await generic(less_raw, sub_scheme)
if (!value.ok) return value
+13 -13
View File
@@ -15,17 +15,17 @@ describe('Object', () => {
describe('empty', () => {
test('Optional', async () => {
const res = await parsing.object(yup.object({thing: yup.number()}))
// @ts-expect-error empty is undefined, duh ??
expect(res).toEqual({ok: true, data: {}})
const res = await parsing.object(yup.object({thing: yup.number()}))
// @ts-expect-error empty is undefined, duh ??
expect(res).toEqual({ok: true, data: {}})
})
test('Required missing', async () => {
const res = await parsing.object(yup.object({thing: yup.number().required()}))
expect(res.ok).not.toBeTrue()
const res = await parsing.object(yup.object({thing: yup.number().required()}))
expect(res.ok).not.toBeTrue()
})
test('default', async () => {
const res = await parsing.object(yup.object({thing: yup.number().default(42)}))
expect(res).toEqual({ok: true, data: {thing: 42}})
const res = await parsing.object(yup.object({thing: yup.number().default(42)}))
expect(res).toEqual({ok: true, data: {thing: 42}})
})
})
@@ -122,13 +122,13 @@ describe('Object', () => {
describe('Specific parsing', () => {
async function testing<T>(env_value: string, scheme: yup.AnySchema, should_be_successful: boolean, thing?: T) {
process.env['THING'] = env_value
const my_scheme = yup.object({thing: scheme})
process.env['THING'] = env_value
const my_scheme = yup.object({thing: scheme})
const res: Ok<{thing: T}> = await parsing.object(my_scheme)
// @ts-expect-error annoying typing issue, but it works, so, yk
if (should_be_successful) expect(res).toEqual({ok: true, data: {thing}})
else expect(res.ok).not.toBeTrue()
const res: Ok<{thing: T}> = await parsing.object(my_scheme)
// @ts-expect-error annoying typing issue, but it works, so, yk
if (should_be_successful) expect(res).toEqual({ok: true, data: {thing}})
else expect(res.ok).not.toBeTrue()
}
describe('array', () => {