@@ -238,6 +238,46 @@ describe('ReactFinalForm', () => {
238238 expect ( renderInput ) . toHaveBeenCalledTimes ( 3 )
239239 expect ( renderInput . mock . calls [ 2 ] [ 0 ] . input . value ) . toBe ( 'bar' )
240240 } )
241+ it ( 'should not reinitialize if initialValues prop is shallow equal' , ( ) => {
242+ const renderInput = jest . fn ( ( { input } ) => < input { ...input } /> )
243+ const lastRenderInputCall = ( ) =>
244+ renderInput . mock . calls [ renderInput . mock . calls . length - 1 ]
245+ class Container extends React . Component {
246+ state = { initValues : { foo : 'bar' } }
247+ render ( ) {
248+ return (
249+ < Form
250+ onSubmit = { onSubmitMock }
251+ subscription = { { dirty : true } }
252+ initialValues = { this . state . initValues }
253+ >
254+ { ( ) => (
255+ < form >
256+ < Field name = "foo" render = { renderInput } />
257+ < button
258+ type = "button"
259+ onClick = { ( ) => this . setState ( { initValues : { foo : 'bar' } } ) }
260+ >
261+ Initialize
262+ </ button >
263+ </ form >
264+ ) }
265+ </ Form >
266+ )
267+ }
268+ }
269+ const dom = TestUtils . renderIntoDocument ( < Container /> )
270+ expect ( renderInput ) . toHaveBeenCalled ( )
271+ expect ( renderInput ) . toHaveBeenCalledTimes ( 1 )
272+ lastRenderInputCall ( ) [ 0 ] . input . onChange ( 'bar!' )
273+ expect ( lastRenderInputCall ( ) [ 0 ] . input . value ) . toBe ( 'bar!' )
274+ const init = TestUtils . findRenderedDOMComponentWithTag ( dom , 'button' )
275+ TestUtils . Simulate . click ( init )
276+
277+ // field should still be edited
278+ const numCalls = renderInput . mock . calls . length
279+ expect ( renderInput . mock . calls [ numCalls - 1 ] [ 0 ] . input . value ) . toBe ( 'bar!' )
280+ } )
241281 it ( 'should respect keepDirtyOnReinitialize prop when initialValues prop changes' , ( ) => {
242282 const renderInput = jest . fn ( ( { input } ) => < input { ...input } /> )
243283 class Container extends React . Component {
@@ -624,7 +664,7 @@ describe('ReactFinalForm', () => {
624664 </ Container >
625665 )
626666 expect ( validate ) . toHaveBeenCalled ( )
627- expect ( validate ) . toHaveBeenCalledTimes ( 2 )
667+ expect ( validate ) . toHaveBeenCalledTimes ( 1 )
628668 } )
629669 it ( 'should add decorators' , ( ) => {
630670 const unsubscribe = jest . fn ( )
0 commit comments