@@ -7,7 +7,7 @@ const defaultProps = {
77 initialValues : {
88 description : '' ,
99 } ,
10- [ ' onSubmit' ] : ( ) => { } ,
10+ onSubmit ( ) { } ,
1111} ;
1212
1313const render = ( ui , props = defaultProps ) => {
@@ -25,14 +25,40 @@ describe('Textarea', () => {
2525 </ > ,
2626 props ,
2727 ) ;
28-
2928 const textarea = getByLabelText ( label ) ;
30- expect ( textarea . value . trim ( ) ) . toBe ( props . initialValues . description ) ;
31-
3229 const value = 'foo' ;
3330
31+ expect ( textarea . value . trim ( ) ) . toBe ( props . initialValues . description ) ;
32+
3433 await fireEvent . change ( textarea , { target : { value} } ) ;
3534
3635 expect ( textarea . value ) . toContain ( value ) ;
3736 } ) ;
37+
38+ test ( '-> changed value is in submitted values' , async ( ) => {
39+ const label = 'description' ;
40+ const submitSpy = jest . fn ( ) ;
41+ const values = { [ label ] : '' } ;
42+ const props = { initialValues : { ...values } , onSubmit : submitSpy } ;
43+ const { getByLabelText, getByRole} = render (
44+ < >
45+ < label for = { label } > { label } </ label >
46+ < Textarea id = { label } name = { label } />
47+
48+ < button type = "submit" > submit</ button >
49+ </ > ,
50+ props ,
51+ ) ;
52+
53+ const textarea = getByLabelText ( label ) ;
54+ const submitButton = getByRole ( 'button' ) ;
55+ const newValue = 'foo' ;
56+
57+ await fireEvent . change ( textarea , { target : { value : newValue } } ) ;
58+ await fireEvent . click ( submitButton ) ;
59+
60+ await waitFor ( ( ) =>
61+ expect ( submitSpy . mock . calls [ 0 ] [ 0 ] ) . toHaveProperty ( label , newValue ) ,
62+ ) ;
63+ } ) ;
3864} ) ;
0 commit comments