I am totally lost with unit testing a change in a textfield. I'm using jest + enzyme to change the textfield but policyEffectiveField.props().value is always null.
I've tried to simulate but using 'change' and 'click' from the formik doc.
policyEffectiveField.simulate('change', {
// you must add this next line as (Formik calls e.persist() internally)
persist: () => {},
// simulate changing e.target.name and e.target.value
target: {
name: 'policyEffectiveDate',
value: "07/30/2019",
},
});
expect(policyEffectiveField.props().value).toEqual(now);
But policyEffectiveField.props().value is null
it('change policyEffectiveDate textfield ', () => {
let now = moment().format('L');
var mountRTI = mount(<TestRTI forms={[policyEffectiveDate]} />);
var policyEffectiveField = mountRTI.find(TextField).find('input').find({ name: 'policyEffectiveDate' });
policyEffectiveField.simulate('change', {
// you must add this next line as (Formik calls e.persist() internally)
persist: () => {},
// simulate changing e.target.name and e.target.value
target: {
name: 'policyEffectiveDate',
value: "07/29/2019",
},
});
expect(policyEffectiveField.props().value).toEqual(now);
});
I expected expect(policyEffectiveField.props().value).toEqual(now); to be true, but I am getting the below error
change policyEffectiveDate textfield
expect(received).toEqual(expected) // deep equality
Expected: "07/30/2019"
Received: undefined
48 | },
49 | });
> 50 | expect(policyEffectiveField.props().value).toEqual(now);