@@ -43,6 +43,8 @@ import {
4343 array as yupArray ,
4444 date as yupDate
4545} from 'yup' ;
46+ import { vine } from '$lib/adapters/vine.js' ;
47+ import Vine from '@vinejs/vine' ;
4648import { traversePath } from '$lib/traversal.js' ;
4749import { splitPath } from '$lib/stringPath.js' ;
4850
@@ -399,6 +401,31 @@ describe('Zod', () => {
399401 schemaTest ( zod ( schema ) ) ;
400402} ) ;
401403
404+ /////////////////////////////////////////////////////////////////////
405+
406+ describe ( 'vine' , ( ) => {
407+ const schema = Vine . object ( {
408+ name : Vine . string ( ) . optional ( ) ,
409+ email : Vine . string ( ) . email ( ) ,
410+ tags : Vine . array ( Vine . string ( ) . minLength ( 2 ) ) . minLength ( 3 ) ,
411+ score : Vine . number ( ) . min ( 0 ) ,
412+ date : Vine . date ( ) . optional ( ) ,
413+ nospace : Vine . string ( ) . regex ( nospacePattern ) . optional ( )
414+ } ) ;
415+
416+ const adapter = vine ( schema , { defaults } ) ;
417+
418+ it ( 'should accept string as input for inferred Date fields' , async ( ) => {
419+ const date = '2024-02-14' ;
420+ const form = await superValidate ( { ...validData , date } , adapter ) ;
421+
422+ const realDate : Date | undefined = form . data . date ;
423+ expect ( realDate ) . toEqual ( new Date ( date + 'T00:00:00' ) ) ;
424+ } ) ;
425+
426+ schemaTest ( adapter , [ 'email' , 'nospace' , 'tags' ] , 'simple' , true ) ;
427+ } ) ;
428+
402429///// Common ////////////////////////////////////////////////////////
403430
404431describe ( 'Schema In/Out transformations' , ( ) => {
@@ -460,11 +487,14 @@ type ErrorFields = ('email' | 'date' | 'nospace' | 'tags' | 'tags[1]')[];
460487function schemaTest (
461488 adapter : ValidationAdapter < Record < string , unknown > , Record < string , unknown > > ,
462489 errors : ErrorFields = [ 'email' , 'nospace' , 'tags' , 'tags[1]' ] ,
463- adapterType : 'full' | 'simple' = 'full'
490+ adapterType : 'full' | 'simple' = 'full' ,
491+ dateAsString : boolean = false
464492) {
493+ const validD = { ...validData , date : dateAsString ? '2024-01-01' : validData . date } ;
494+
465495 // eslint-disable-next-line @typescript-eslint/no-explicit-any
466496 function expectErrors ( errors : ErrorFields , errorMessages : Record < string , any > ) {
467- //console.log('🚀 ~ expectErrors ~ errorMessages:', errorMessages);
497+ // console.log('🚀 ~ expectErrors ~ errorMessages:', errorMessages);
468498
469499 if ( errors . includes ( 'nospace' ) ) expect ( errorMessages . nospace ) . toBeTruthy ( ) ;
470500 if ( errors . includes ( 'email' ) ) expect ( errorMessages . email ) . toBeTruthy ( ) ;
@@ -530,11 +560,14 @@ function schemaTest(
530560 } ) ;
531561
532562 it ( 'with valid test data' , async ( ) => {
533- const output = await superValidate ( validData , adapter ) ;
563+ const output = await superValidate ( validD , adapter ) ;
534564 expect ( output . errors ) . toEqual ( { } ) ;
535565 expect ( output . valid ) . toEqual ( true ) ;
536- expect ( output . data ) . not . toBe ( validData ) ;
537- expect ( output . data ) . toEqual ( validData ) ;
566+ expect ( output . data ) . not . toBe ( validD ) ;
567+ expect ( output . data ) . toEqual ( {
568+ ...validD ,
569+ date : dateAsString ? new Date ( validD . date + 'T00:00:00' ) : validD . date
570+ } ) ;
538571 expect ( output . message ) . toBeUndefined ( ) ;
539572 expectConstraints ( output . constraints ) ;
540573 } ) ;
0 commit comments