Skip to content

Commit

Permalink
chore: address comments to leave tuple unsupported
Browse files Browse the repository at this point in the history
  • Loading branch information
gglee89 committed Apr 2, 2024
1 parent 8dae394 commit b24f0e1
Showing 1 changed file with 3 additions and 29 deletions.
32 changes: 3 additions & 29 deletions tests/conform-yup.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,6 @@ import * as yup from 'yup';
import { type Constraint, STATE } from '@conform-to/dom';
import { createFormData } from './helpers';

// Adding custom method tuple until Yup is updated to v1 where the tuple method is built-in
// ref: https://github.com/jquense/yup/issues/528#issuecomment-916885944
yup.addMethod(yup.array, 'tuple', function (schema) {
if (!this.isType(schema)) yup.ValidationError();
return yup.object({
...Object.fromEntries(Object.entries(schema)),
});
});

describe('conform-yup', () => {
const maxDate = new Date();
const schema = yup
Expand All @@ -36,7 +27,8 @@ describe('conform-yup', () => {
yup.string().required('required').oneOf(['a', 'b', 'c'], 'invalid'),
)
.required('required')
.min(3, 'min'),
.min(3, 'min')
.test('nested', 'error', () => false),
nested: yup
.object({
key: yup.string().required('required'),
Expand All @@ -53,13 +45,6 @@ describe('conform-yup', () => {
)
.required('required')
.max(0, 'max'),
tuple: yup
.array()
.tuple([
yup.string().required('required').min(3),
yup.number().notRequired().max(100),
])
.required(),
})
.test('root', 'error', () => false);

Expand All @@ -78,12 +63,11 @@ describe('conform-yup', () => {
number: ['max'],
timestamp: ['min'],
'options[1]': ['invalid'],
options: ['min'],
options: ['min', 'error'],
'nested.key': ['required'],
'list[0].key': ['required'],
'list[0]': ['error'],
list: ['max'],
'tuple.0': ['required'],
'': ['error'],
};

Expand Down Expand Up @@ -133,16 +117,6 @@ describe('conform-yup', () => {
'list[].key': {
required: true,
},
tuple: {
required: true,
},
'tuple.0': {
required: true,
minLength: 3,
},
'tuple.1': {
max: 100,
},
};

expect(getYupConstraint(schema)).toEqual(constraint);
Expand Down

0 comments on commit b24f0e1

Please sign in to comment.