@@ -100,10 +100,14 @@ describe('Field / FastField', () => {
100
100
101
101
describe ( 'renders an <input /> by default' , ( ) => {
102
102
it ( '<Field />' , ( ) => {
103
- const className = 'field-custom'
104
- const { container } = renderForm ( < Field name = "name" className = { className } /> ) ;
103
+ const className = 'field-custom' ;
104
+ const { container } = renderForm (
105
+ < Field name = "name" className = { className } />
106
+ ) ;
105
107
expect ( container . querySelectorAll ( 'input' ) ) . toHaveLength ( 1 ) ;
106
- expect ( container . querySelector ( `.${ className } ` ) ?. getAttribute ( 'value' ) ) . toEqual ( 'jared' )
108
+ expect (
109
+ container . querySelector ( `.${ className } ` ) ?. getAttribute ( 'value' )
110
+ ) . toEqual ( 'jared' ) ;
107
111
} ) ;
108
112
109
113
it ( '<FastField />' , ( ) => {
@@ -112,22 +116,6 @@ describe('Field / FastField', () => {
112
116
} ) ;
113
117
} ) ;
114
118
115
- describe ( 'renders an <input /> with className' , ( ) => {
116
- it ( '<Field />' , ( ) => {
117
- const className = 'field-custom'
118
- const { container } = renderForm ( < Field name = "name" className = { className } /> ) ;
119
- expect ( container . querySelectorAll ( `.${ className } ` ) ) . toHaveLength ( 1 )
120
- expect ( container . querySelector ( `.${ className } ` ) ?. getAttribute ( 'value' ) ) . toEqual ( 'jared' )
121
- } ) ;
122
-
123
- it ( '<FastField />' , ( ) => {
124
- const className = 'field-custom'
125
- const { container } = renderForm ( < FastField name = "name" className = { className } /> ) ;
126
- expect ( container . querySelectorAll ( `.${ className } ` ) ) . toHaveLength ( 1 )
127
- expect ( container . querySelector ( `.${ className } ` ) ?. getAttribute ( 'value' ) ) . toEqual ( 'jared' )
128
- } ) ;
129
- } ) ;
130
-
131
119
describe ( 'receives { field, form, meta } props and renders element' , ( ) => {
132
120
it ( '<Field />' , ( ) => {
133
121
let injected : FieldProps [ ] = [ ] ;
@@ -222,7 +210,7 @@ describe('Field / FastField', () => {
222
210
} ) ;
223
211
224
212
describe ( 'children' , ( ) => {
225
- cases ( 'renders a child element with component' , ( ) => {
213
+ it ( 'renders a child element with component' , ( ) => {
226
214
const { container } = renderForm (
227
215
< Field name = "name" component = "select" >
228
216
< option value = "Jared" label = { TEXT } />
@@ -233,7 +221,7 @@ describe('Field / FastField', () => {
233
221
expect ( container . querySelectorAll ( 'option' ) ) . toHaveLength ( 2 ) ;
234
222
} ) ;
235
223
236
- cases ( 'renders a child element with as' , ( ) => {
224
+ it ( 'renders a child element with as' , ( ) => {
237
225
const { container } = renderForm (
238
226
< Field name = "name" as = "select" >
239
227
< option value = "Jared" label = { TEXT } />
@@ -604,6 +592,48 @@ describe('Field / FastField', () => {
604
592
605
593
expect ( getProps ( ) . field . value ) . toBe ( 'Binding' ) ;
606
594
} ) ;
595
+
596
+ describe ( 'renders an <input /> with className' , ( ) => {
597
+ it ( '<Field />' , ( ) => {
598
+ const className = 'field-custom' ;
599
+ const { container } = renderForm (
600
+ < Field name = "name" className = { className } />
601
+ ) ;
602
+ expect ( container . querySelectorAll ( `.${ className } ` ) ) . toHaveLength ( 1 ) ;
603
+ expect (
604
+ container . querySelector ( `.${ className } ` ) ?. getAttribute ( 'value' )
605
+ ) . toEqual ( 'jared' ) ;
606
+ } ) ;
607
+
608
+ it ( '<FastField />' , ( ) => {
609
+ const className = 'field-custom' ;
610
+ const { container } = renderForm (
611
+ < FastField name = "name" className = { className } />
612
+ ) ;
613
+ expect ( container . querySelectorAll ( `.${ className } ` ) ) . toHaveLength ( 1 ) ;
614
+ expect (
615
+ container . querySelector ( `.${ className } ` ) ?. getAttribute ( 'value' )
616
+ ) . toEqual ( 'jared' ) ;
617
+ } ) ;
618
+ } ) ;
619
+ cases (
620
+ "render custom component and doesn't overwrite className" ,
621
+ renderField => {
622
+ const { container } = renderField ( {
623
+ children : ( { form, field, ...reset } ) => (
624
+ /**
625
+ * @see https://github.com/jaredpalmer/formik/issues/3883
626
+ * ensure when Field or FastField component don't review classNames,
627
+ * they won't pass {className:undefined} to custom component
628
+ *
629
+ */
630
+ < input name = "name" className = "custom-class" { ...reset } />
631
+ ) ,
632
+ } ) ;
633
+
634
+ expect ( container . querySelector ( '.custom-class' ) ) . toBeTruthy ( ) ;
635
+ }
636
+ ) ;
607
637
} ) ;
608
638
609
639
// @todo Deprecated
0 commit comments