File tree Expand file tree Collapse file tree 2 files changed +18
-1
lines changed Expand file tree Collapse file tree 2 files changed +18
-1
lines changed Original file line number Diff line number Diff line change @@ -30,4 +30,20 @@ describe('joiResolver', () => {
3030 it ( 'should return errors' , async ( ) => {
3131 expect ( await joiResolver ( schema ) ( { } ) ) . toMatchSnapshot ( ) ;
3232 } ) ;
33+
34+ it ( 'should validate with context' , async ( ) => {
35+ const schemaSpy = jest . spyOn ( schema , 'validateAsync' ) ;
36+ const context = { value : 'context' } ;
37+
38+ const data = { username : 'abc' , birthYear : 1994 } ;
39+ expect ( await joiResolver ( schema ) ( data , context ) ) . toEqual ( {
40+ values : data ,
41+ errors : { } ,
42+ } ) ;
43+
44+ expect ( schemaSpy ) . toHaveBeenCalledWith ( data , {
45+ abortEarly : false ,
46+ context,
47+ } ) ;
48+ } ) ;
3349} ) ;
Original file line number Diff line number Diff line change @@ -54,13 +54,14 @@ export const joiResolver = <TFieldValues extends FieldValues>(
5454 } ,
5555) : Resolver < TFieldValues > => async (
5656 values ,
57- _ ,
57+ context ,
5858 validateAllFieldCriteria = false ,
5959) => {
6060 try {
6161 return {
6262 values : await schema . validateAsync ( values , {
6363 ...options ,
64+ context,
6465 } ) ,
6566 errors : { } ,
6667 } ;
You can’t perform that action at this time.
0 commit comments