From 17f60418b1a56b5f712625714059eff4b895d91e Mon Sep 17 00:00:00 2001 From: erikras-dinesh-agent Date: Tue, 17 Feb 2026 04:29:51 +0100 Subject: [PATCH] Test: regression tests for submitting stuck on Promise onSubmit (#903) --- src/ReactFinalForm.test.js | 57 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) diff --git a/src/ReactFinalForm.test.js b/src/ReactFinalForm.test.js index 5b6c575..af0e76d 100644 --- a/src/ReactFinalForm.test.js +++ b/src/ReactFinalForm.test.js @@ -990,4 +990,61 @@ describe("ReactFinalForm", () => { fireEvent.focus(getByTestId("password")); expect(getByTestId("password").value).toBe("f1nal-f0rm-RULEZ"); }); + + it("should set submitting back to false when onSubmit returns Promise.resolve() immediately (#903)", async () => { + // Regression test for: https://github.com/final-form/react-final-form/issues/903 + // When onSubmit is an async function with no awaits (returns Promise), + // submitting should reset to false after the promise resolves. + const onSubmit = jest.fn(async () => { + // async with no await — resolves in the next microtask, no real async delay + }); + const recordSubmitting = jest.fn(); + const { getByText } = render( +
+ {({ handleSubmit, submitting }) => { + recordSubmitting(submitting); + return ( + + + + + ); + }} + , + ); + + fireEvent.click(getByText("Submit")); + + // Wait for the microtask Promise to resolve and React to update + await act(async () => {}); + + // submitting should have gone true then back to false + const calls = recordSubmitting.mock.calls.map((c) => c[0]); + expect(calls).toContain(true); // was submitting at some point + expect(calls[calls.length - 1]).toBe(false); // ends as not submitting + }); + + it("should set submitting back to false when onSubmit returns Promise.resolve() (#903)", async () => { + const onSubmit = jest.fn(() => Promise.resolve()); + const recordSubmitting = jest.fn(); + const { getByText } = render( +
+ {({ handleSubmit, submitting }) => { + recordSubmitting(submitting); + return ( + + + + + ); + }} + , + ); + + fireEvent.click(getByText("Submit")); + await act(async () => {}); + + const calls = recordSubmitting.mock.calls.map((c) => c[0]); + expect(calls[calls.length - 1]).toBe(false); + }); });