@@ -10,19 +10,31 @@ console.error = jest.fn();
1010
1111const withFormikMock = withContext ( { formik : PropTypes . object } , ( ) => ( {
1212 formik : {
13- errors : { errored : "This is an error" }
13+ errors : {
14+ email : "This is not a valid email." ,
15+ user : {
16+ password : "Password is too short!"
17+ }
18+ }
1419 }
1520} ) ) ;
1621const Input = compose ( withFormikMock , withError ) ( TextInput ) ;
1722
1823describe ( "withError" , ( ) => {
1924 it ( "sets the error prop" , ( ) => {
20- const erroredInput = mount ( < Input name = "errored " /> ) ;
21- expect ( erroredInput . find ( TextInput ) . props ( ) . error ) . toEqual ( "This is an error " ) ;
25+ const erroredInput = mount ( < Input name = "email " /> ) ;
26+ expect ( erroredInput . find ( TextInput ) . props ( ) . error ) . toEqual ( "This is not a valid email. " ) ;
2227 const validInput = mount ( < Input name = "valid" /> ) ;
2328 expect ( validInput . find ( TextInput ) . props ( ) . error ) . toBeFalsy ( ) ;
2429 } ) ;
2530
31+ it ( 'sets the error prop for nested key name' , ( ) => {
32+ const emailInput = mount ( < Input name = "user.password" /> ) ;
33+ expect ( emailInput . find ( TextInput ) . props ( ) . error ) . toEqual ( "Password is too short!" ) ;
34+ const otherInput = mount ( < Input name = "user.username" /> ) ;
35+ expect ( otherInput . find ( TextInput ) . props ( ) . error ) . toEqual ( undefined ) ;
36+ } ) ;
37+
2638 it ( "keeps other props" , ( ) => {
2739 const wrapper = mount ( < Input name = "inputName" someProp = "someValue" /> ) ;
2840 expect ( wrapper . find ( TextInput ) . props ( ) . someProp ) . toEqual ( "someValue" ) ;
0 commit comments