@@ -236,6 +236,44 @@ describe('ReactFinalForm', () => {
236236 expect ( renderInput ) . toHaveBeenCalledTimes ( 2 )
237237 expect ( renderInput . mock . calls [ 1 ] [ 0 ] . input . value ) . toBe ( 'bar' )
238238 } )
239+ it ( 'should respect keepDirtyOnReinitialize prop when initialValues prop changes' , ( ) => {
240+ const renderInput = jest . fn ( ( { input } ) => < input { ...input } /> )
241+ class Container extends React . Component {
242+ state = { initValues : { foo : 'bar' } }
243+ render ( ) {
244+ return (
245+ < Form
246+ onSubmit = { onSubmitMock }
247+ subscription = { { dirty : true } }
248+ keepDirtyOnReinitialize = { true }
249+ initialValues = { this . state . initValues }
250+ >
251+ { ( ) => (
252+ < form >
253+ < Field name = "foo" render = { renderInput } />
254+ < button
255+ type = "button"
256+ onClick = { ( ) => this . setState ( { initValues : { foo : 'bar' } } ) }
257+ >
258+ Initialize
259+ </ button >
260+ </ form >
261+ ) }
262+ </ Form >
263+ )
264+ }
265+ }
266+ const dom = TestUtils . renderIntoDocument ( < Container /> )
267+ expect ( renderInput ) . toHaveBeenCalled ( )
268+ expect ( renderInput ) . toHaveBeenCalledTimes ( 1 )
269+ const input = TestUtils . findRenderedDOMComponentWithTag ( dom , 'input' )
270+ TestUtils . Simulate . change ( input , { target : { value : 'baz' } } )
271+ expect ( renderInput ) . toHaveBeenCalledTimes ( 2 )
272+ const init = TestUtils . findRenderedDOMComponentWithTag ( dom , 'button' )
273+ TestUtils . Simulate . click ( init )
274+ expect ( renderInput ) . toHaveBeenCalledTimes ( 3 )
275+ expect ( renderInput . mock . calls [ 1 ] [ 0 ] . input . value ) . toBe ( 'baz' )
276+ } )
239277 it ( 'should update when onSubmit changes' , async ( ) => {
240278 const oldOnSubmit = jest . fn ( )
241279 const newOnSubmit = jest . fn ( )
0 commit comments