@@ -5,9 +5,9 @@ import { ErrorBoundary, Toggle, wrapWith } from './testUtils'
5
5
import Form from './ReactFinalForm'
6
6
import Field from './Field'
7
7
8
- const onSubmitMock = values => { }
8
+ const onSubmitMock = ( values ) => { }
9
9
10
- const timeout = ms => new Promise ( resolve => setTimeout ( resolve , ms ) )
10
+ const timeout = ( ms ) => new Promise ( ( resolve ) => setTimeout ( resolve , ms ) )
11
11
async function sleep ( ms ) {
12
12
await act ( async ( ) => {
13
13
await timeout ( ms )
@@ -36,7 +36,7 @@ describe('Field', () => {
36
36
it ( 'should resubscribe if name changes' , ( ) => {
37
37
const { getByTestId, getByText } = render (
38
38
< Toggle >
39
- { isCat => (
39
+ { ( isCat ) => (
40
40
< Form
41
41
onSubmit = { onSubmitMock }
42
42
initialValues = { { dog : 'Odie' , cat : 'Garfield' } }
@@ -129,7 +129,7 @@ describe('Field', () => {
129
129
// This is mainly here for code coverage. 🧐
130
130
const { getByText } = render (
131
131
< Toggle >
132
- { hidden => (
132
+ { ( hidden ) => (
133
133
< Form
134
134
onSubmit = { onSubmitMock }
135
135
initialValues = { { dog : 'Odie' , cat : 'Garfield' } }
@@ -208,7 +208,7 @@ describe('Field', () => {
208
208
< Form onSubmit = { onSubmitMock } subscription = { { values : true } } >
209
209
{ wrapWith ( spy , ( ) => (
210
210
< form >
211
- < Field name = "name" parse = { v => v } >
211
+ < Field name = "name" parse = { ( v ) => v } >
212
212
{ ( { input : { value, ...props } } ) => (
213
213
< input
214
214
{ ...props }
@@ -241,7 +241,7 @@ describe('Field', () => {
241
241
< Field
242
242
name = "name"
243
243
component = "input"
244
- format = { value => ( value ? value . toUpperCase ( ) : '' ) }
244
+ format = { ( value ) => ( value ? value . toUpperCase ( ) : '' ) }
245
245
data-testid = "name"
246
246
/>
247
247
</ form >
@@ -258,7 +258,7 @@ describe('Field', () => {
258
258
} )
259
259
260
260
it ( 'should only format on blur if formatOnBlur is true' , ( ) => {
261
- const format = jest . fn ( value => ( value ? value . toUpperCase ( ) : '' ) )
261
+ const format = jest . fn ( ( value ) => ( value ? value . toUpperCase ( ) : '' ) )
262
262
const { getByTestId } = render (
263
263
< Form onSubmit = { onSubmitMock } subscription = { { values : true } } >
264
264
{ ( ) => (
@@ -286,7 +286,7 @@ describe('Field', () => {
286
286
} )
287
287
288
288
it ( 'should `formatOnBlur` most updated value' , ( ) => {
289
- const format = jest . fn ( value => ( value ? value . trim ( ) : '' ) )
289
+ const format = jest . fn ( ( value ) => ( value ? value . trim ( ) : '' ) )
290
290
const { getByTestId } = render (
291
291
< Form onSubmit = { onSubmitMock } subscription = { { values : true } } >
292
292
{ ( ) => (
@@ -296,7 +296,7 @@ describe('Field', () => {
296
296
< input
297
297
{ ...input }
298
298
data-testid = "name"
299
- onBlur = { e => {
299
+ onBlur = { ( e ) => {
300
300
input . onChange (
301
301
e . target . value && e . target . value . toUpperCase ( )
302
302
)
@@ -320,7 +320,7 @@ describe('Field', () => {
320
320
} )
321
321
322
322
it ( 'should not format value at all when formatOnBlur and render prop' , ( ) => {
323
- const format = jest . fn ( value => ( value ? value . toUpperCase ( ) : '' ) )
323
+ const format = jest . fn ( ( value ) => ( value ? value . toUpperCase ( ) : '' ) )
324
324
render (
325
325
< Form onSubmit = { onSubmitMock } subscription = { { values : true } } >
326
326
{ ( ) => (
@@ -344,7 +344,7 @@ describe('Field', () => {
344
344
< Form onSubmit = { onSubmitMock } subscription = { { values : true } } >
345
345
{ ( ) => (
346
346
< form >
347
- < Field name = "name" format = { v => v } >
347
+ < Field name = "name" format = { ( v ) => v } >
348
348
{ wrapWith ( spy , ( { input : { value, ...props } } ) => (
349
349
< input
350
350
{ ...props }
@@ -551,8 +551,8 @@ describe('Field', () => {
551
551
} )
552
552
553
553
it ( 'should allow changing field-level validation function' , ( ) => {
554
- const simpleValidate = value => ( value ? undefined : 'Required' )
555
- const complexValidate = value => {
554
+ const simpleValidate = ( value ) => ( value ? undefined : 'Required' )
555
+ const complexValidate = ( value ) => {
556
556
if ( value ) {
557
557
if ( value !== value . toUpperCase ( ) ) {
558
558
return 'SHOULD BE UPPERCASE!'
@@ -563,7 +563,7 @@ describe('Field', () => {
563
563
}
564
564
const { getByTestId, getByText } = render (
565
565
< Toggle >
566
- { useComplexValidation => (
566
+ { ( useComplexValidation ) => (
567
567
< Form onSubmit = { onSubmitMock } >
568
568
{ ( { handleSubmit } ) => (
569
569
< form onSubmit = { handleSubmit } >
@@ -610,8 +610,8 @@ describe('Field', () => {
610
610
* form.
611
611
*/
612
612
it ( 'should ignore changes field-level validation function' , ( ) => {
613
- const createValidator = isRequired =>
614
- isRequired ? value => ( value ? undefined : 'Required' ) : undefined
613
+ const createValidator = ( isRequired ) =>
614
+ isRequired ? ( value ) => ( value ? undefined : 'Required' ) : undefined
615
615
616
616
const Error = ( { name } ) => (
617
617
< Field name = { name } subscription = { { error : true } } >
@@ -620,7 +620,7 @@ describe('Field', () => {
620
620
)
621
621
const { getByTestId, getByText } = render (
622
622
< Toggle >
623
- { isRequired => (
623
+ { ( isRequired ) => (
624
624
< Form onSubmit = { onSubmitMock } >
625
625
{ ( { handleSubmit } ) => (
626
626
< form onSubmit = { handleSubmit } >
@@ -656,7 +656,7 @@ describe('Field', () => {
656
656
657
657
it ( 'should not rerender if validateFields is !== every time' , ( ) => {
658
658
// https://github.com/final-form/react-final-form/issues/502
659
- const required = value => ( value ? undefined : 'Required' )
659
+ const required = ( value ) => ( value ? undefined : 'Required' )
660
660
const spy = jest . fn ( )
661
661
const { getByTestId } = render (
662
662
< Form onSubmit = { onSubmitMock } >
@@ -1038,7 +1038,7 @@ describe('Field', () => {
1038
1038
< Field
1039
1039
name = "name"
1040
1040
component = "input"
1041
- format = { value => value && value . toUpperCase ( ) }
1041
+ format = { ( value ) => value && value . toUpperCase ( ) }
1042
1042
formatOnBlur
1043
1043
data-testid = "name"
1044
1044
/>
@@ -1107,7 +1107,7 @@ describe('Field', () => {
1107
1107
< Field
1108
1108
name = "name"
1109
1109
component = "input"
1110
- validate = { async value => {
1110
+ validate = { async ( value ) => {
1111
1111
await timeout ( 5 )
1112
1112
return value === 'erikras' ? 'Username taken' : undefined
1113
1113
} }
@@ -1152,7 +1152,7 @@ describe('Field', () => {
1152
1152
const validate = jest . fn ( )
1153
1153
const { getByText } = render (
1154
1154
< Toggle >
1155
- { showOtherFields => (
1155
+ { ( showOtherFields ) => (
1156
1156
< Form onSubmit = { onSubmitMock } validate = { validate } >
1157
1157
{ ( { handleSubmit } ) => (
1158
1158
< form onSubmit = { handleSubmit } >
@@ -1184,13 +1184,13 @@ describe('Field', () => {
1184
1184
it ( 'submit should not throw when field with enabled `formatOnBlur` changes name `prop`' , ( ) => {
1185
1185
const onSubmit = jest . fn ( )
1186
1186
1187
- const trim = value => value && value . trim ( )
1187
+ const trim = ( value ) => value && value . trim ( )
1188
1188
1189
1189
const { getByTestId, getByText } = render (
1190
1190
< Form onSubmit = { onSubmit } >
1191
1191
{ ( { handleSubmit } ) => (
1192
1192
< Toggle >
1193
- { newFieldName => (
1193
+ { ( newFieldName ) => (
1194
1194
< form onSubmit = { handleSubmit } >
1195
1195
< Field
1196
1196
name = { newFieldName ? 'newName' : 'oldName' }
@@ -1215,4 +1215,24 @@ describe('Field', () => {
1215
1215
expect ( onSubmit ) . toHaveBeenCalled ( )
1216
1216
expect ( onSubmit . mock . calls [ 0 ] [ 0 ] ) . toEqual ( { newName : 'trailing space' } )
1217
1217
} )
1218
+
1219
+ it ( 'should throw an error if name prop is undefined' , ( ) => {
1220
+ jest . spyOn ( console , 'error' ) . mockImplementation ( ( ) => { } )
1221
+
1222
+ const errorSpy = jest . fn ( )
1223
+ render (
1224
+ < ErrorBoundary spy = { errorSpy } >
1225
+ < Form onSubmit = { onSubmitMock } >
1226
+ { ( ) => < Field name = { undefined } render = { ( ) => < input /> } /> }
1227
+ </ Form >
1228
+ </ ErrorBoundary >
1229
+ )
1230
+
1231
+ expect ( errorSpy ) . toHaveBeenCalled ( )
1232
+ expect ( errorSpy ) . toHaveBeenCalledTimes ( 1 )
1233
+ expect ( errorSpy . mock . calls [ 0 ] [ 0 ] . message ) . toBe (
1234
+ 'prop name cannot be undefined in <Field> component'
1235
+ )
1236
+ console . error . mockRestore ( )
1237
+ } )
1218
1238
} )
0 commit comments