diff --git a/src/parsing.ts b/src/parsing.ts index 79e3e40..ca80920 100644 --- a/src/parsing.ts +++ b/src/parsing.ts @@ -44,7 +44,8 @@ export async function object>( } } 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 diff --git a/test/parsing.test.ts b/test/parsing.test.ts index e7a3e54..ee3941d 100644 --- a/test/parsing.test.ts +++ b/test/parsing.test.ts @@ -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(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', () => {