@@ -19,7 +19,7 @@ const options = [
1919 { text : 'Socks' , value : 'socks' } ,
2020] ;
2121
22- const TestForm = ( ) => (
22+ const TestForm = ( { onChange } : { onChange : any } ) => (
2323 < Form >
2424 < FormsyDropdown
2525 label = { < span data-testid = "label" > Clothing</ span > }
@@ -30,15 +30,18 @@ const TestForm = () => (
3030 validationErrors = { {
3131 isDefaultRequiredValue : validationError ,
3232 } }
33+ onChange = { onChange }
3334 />
3435 </ Form >
3536) ;
3637
3738describe ( '<Dropdown/>' , ( ) => {
3839 let wrapper : RenderResult ;
40+ let onChangeSpy : jest . Mock ;
3941
4042 beforeEach ( ( ) => {
41- wrapper = render ( < TestForm /> ) ;
43+ onChangeSpy = jest . fn ( ) ;
44+ wrapper = render ( < TestForm onChange = { onChangeSpy } /> ) ;
4245 } ) ;
4346
4447 const submitForm = ( ) => {
@@ -61,6 +64,14 @@ describe('<Dropdown/>', () => {
6164 } ) ;
6265 } ) ;
6366
67+ it ( 'should add `name` prop to onChange dropdown props' , ( ) => {
68+ selectOptionAt ( 1 ) ;
69+ expect ( onChangeSpy ) . toHaveBeenCalledWith (
70+ expect . anything ( ) ,
71+ expect . objectContaining ( { name : 'testInput' , value : options [ 1 ] . value } )
72+ ) ;
73+ } ) ;
74+
6475 describe ( 'When value is invalid' , ( ) => {
6576 it ( "Doesn't show any errors initially" , ( ) => {
6677 expect ( wrapper . queryByTestId ( 'error-label' ) ) . not . toBeInTheDocument ( ) ;
0 commit comments