I'm trying to test one of my app Formik inputs using Enzyme and Jest,
describe("<VehicleForm />", () => {
it("renders correctly", async () => {
const wrapper = shallow(<VehicleFormIcon />);
const nameInput = wrapper.find(Formik).dive().find("[name='inputName']");
nameInput.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: "inputName",
value: "ian",
},
});
await expect(nameInput.props().value).toEqual("ian");
});
when running npm test i get
expect(received).toEqual(expected) // deep equality
Expected: "ian"
Received: ""
if i do console.log(nameInput.props()) i receive,
{
name: 'inputName',
style: { marginHorizontal: 20, marginBottom: 15 },
value: '',
status: 'basic',
label: 'Nombre cliente',
autoCapitalize: 'words',
placeholder: 'Ingrese el nombre del cliente',
onBlur: [Function: onBlur],
onChangeText: [Function (anonymous)],
returnKeyType: 'next',
onSubmitEditing: [Function: onSubmitEditing],
blurOnSubmit: false,
caption: [Function: caption]
}
so at least the wrapper contains the input that i'm looking to simulate. Why the simulate function doesnt change the value of the input?