Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions packages/formik/src/Formik.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -797,6 +797,9 @@ export function useFormik<Values extends FormikValues = FormikValues>({
// throw combinedErrors;
if (isInstanceOfError) {
throw combinedErrors;
} else {
// need to fulfill contract: submitForm will throw if validation fails
throw new Error();
}
}
return;
Expand Down
15 changes: 15 additions & 0 deletions packages/formik/test/Formik.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -609,6 +609,21 @@ describe('<Formik>', () => {
);
});
});
it('submit should reject if validate returns error', async () => {
const onSubmit = jest.fn();
const validate = jest.fn().mockResolvedValue({ error: 'error' });
// expect(global.console.warn).not.toHaveBeenCalled();

const { getProps } = renderFormik({ onSubmit, validate });

await act(async () => {
await expect(getProps().submitForm()).rejects.toThrow();
});

await waitFor(() => {
expect(onSubmit).not.toBeCalled();
});
});
});

describe('with validationSchema (ASYNC)', () => {
Expand Down
Loading