@@ -19,7 +19,7 @@ const options = [
19
19
{ text : 'Socks' , value : 'socks' } ,
20
20
] ;
21
21
22
- const TestForm = ( ) => (
22
+ const TestForm = ( { onChange } : { onChange : any } ) => (
23
23
< Form >
24
24
< FormsyDropdown
25
25
label = { < span data-testid = "label" > Clothing</ span > }
@@ -30,15 +30,18 @@ const TestForm = () => (
30
30
validationErrors = { {
31
31
isDefaultRequiredValue : validationError ,
32
32
} }
33
+ onChange = { onChange }
33
34
/>
34
35
</ Form >
35
36
) ;
36
37
37
38
describe ( '<Dropdown/>' , ( ) => {
38
39
let wrapper : RenderResult ;
40
+ let onChangeSpy : jest . Mock ;
39
41
40
42
beforeEach ( ( ) => {
41
- wrapper = render ( < TestForm /> ) ;
43
+ onChangeSpy = jest . fn ( ) ;
44
+ wrapper = render ( < TestForm onChange = { onChangeSpy } /> ) ;
42
45
} ) ;
43
46
44
47
const submitForm = ( ) => {
@@ -61,6 +64,14 @@ describe('<Dropdown/>', () => {
61
64
} ) ;
62
65
} ) ;
63
66
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
+
64
75
describe ( 'When value is invalid' , ( ) => {
65
76
it ( "Doesn't show any errors initially" , ( ) => {
66
77
expect ( wrapper . queryByTestId ( 'error-label' ) ) . not . toBeInTheDocument ( ) ;
0 commit comments