fmt
This commit is contained in:
+2
-1
@@ -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
@@ -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', () => {
|
||||
|
||||
Reference in New Issue
Block a user