Skip to content

Commit e1fe376

Browse files
committed
chore(makeReactNativeField): add tests for onBlur handling
1 parent 90b4a99 commit e1fe376

1 file changed

Lines changed: 20 additions & 3 deletions

File tree

src/__tests__/makeReactNativeField.js

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,13 +62,30 @@ describe("makeReactNativeField", () => {
6262
expect(setFieldValue).toHaveBeenCalledWith("email", "New text");
6363
});
6464

65-
it("handles input touch event", () => {
65+
it("handles input touch event to set field as touched and validate", () => {
6666
const wrapper = mount(<Input name="email" />);
6767
wrapper
6868
.find(TextInput)
6969
.props()
7070
.onBlur();
71-
expect(setFieldTouched).toHaveBeenCalledWith("email");
71+
expect(setFieldTouched).toHaveBeenCalledWith("email", true, true);
72+
});
73+
74+
it("does not validate on field blur if form is submitting", () => {
75+
const formikContextSubmitting = {
76+
setFieldTouched,
77+
isSubmitting: true
78+
};
79+
const InputInSubmittingForm = compose(
80+
withFormikMock(formikContextSubmitting),
81+
makeReactNativeField
82+
)(TextInput);
83+
const wrapper = mount(<InputInSubmittingForm name="email" />);
84+
wrapper
85+
.find(TextInput)
86+
.props()
87+
.onBlur();
88+
expect(setFieldTouched).toHaveBeenCalledWith("email", true, false);
7289
});
7390

7491
it("allows override of onBlur", () => {
@@ -78,7 +95,7 @@ describe("makeReactNativeField", () => {
7895
.find(TextInput)
7996
.props()
8097
.onBlur();
81-
expect(setFieldTouched).toHaveBeenCalledWith("email");
98+
expect(setFieldTouched).toHaveBeenCalledWith("email", true, true);
8299
expect(onBlur).toHaveBeenCalled();
83100
});
84101
});

0 commit comments

Comments
 (0)