Skip to content

Commit 9a26a17

Browse files
committed
Add test to confirm initialValues higher priority
1 parent a5ab931 commit 9a26a17

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

packages/react-form-renderer/src/tests/form-renderer/render-form.test.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1723,4 +1723,34 @@ describe('renderForm function', () => {
17231723
expect(wrapper.find('label').text()).toEqual(label);
17241724
expect(wrapper.find('label').props().id).toEqual(id);
17251725
});
1726+
1727+
describe('#initialValues', () => {
1728+
it('initialValues has a higher priority than initialValue', () => {
1729+
const onSubmit = jest.fn();
1730+
const wrapper = mount(
1731+
<FormRenderer
1732+
FormTemplate={(props) => <FormTemplate {...props} />}
1733+
componentMapper={{
1734+
'custom-component': TextField,
1735+
}}
1736+
schema={{
1737+
fields: [
1738+
{
1739+
component: 'custom-component',
1740+
name: 'testField',
1741+
initialValue: 'lower-priority',
1742+
},
1743+
],
1744+
}}
1745+
onSubmit={(values) => onSubmit(values)}
1746+
initialValues={{ testField: 'higher-priority' }}
1747+
/>
1748+
);
1749+
1750+
expect(wrapper.find('input').instance().value).toEqual('higher-priority');
1751+
1752+
wrapper.find('form').simulate('submit');
1753+
expect(onSubmit).toHaveBeenCalledWith({ testField: 'higher-priority' });
1754+
});
1755+
});
17261756
});

0 commit comments

Comments
 (0)