Add test for multiple form submissions (#33059)

Test for #30041 and #33055
This commit is contained in:
Matt Carroll 2025-05-05 14:47:47 -07:00 committed by GitHub
parent edf550b679
commit 79586c7eb6
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -1670,6 +1670,37 @@ describe('ReactDOMForm', () => {
expect(divRef.current.textContent).toEqual('Current username: acdlite'); expect(divRef.current.textContent).toEqual('Current username: acdlite');
}); });
it('parallel form submissions do not throw', async () => {
const formRef = React.createRef();
let resolve = null;
function App() {
async function submitForm() {
Scheduler.log('Action');
if (!resolve) {
await new Promise(res => {
resolve = res;
});
}
}
return <form ref={formRef} action={submitForm} />;
}
const root = ReactDOMClient.createRoot(container);
await act(() => root.render(<App />));
// Start first form submission
await act(async () => {
formRef.current.requestSubmit();
});
assertLog(['Action']);
// Submit form again while first form action is still pending
await act(async () => {
formRef.current.requestSubmit();
resolve(); // Resolve the promise to allow the first form action to complete
});
assertLog(['Action']);
});
it( it(
'requestFormReset works with inputs that are not descendants ' + 'requestFormReset works with inputs that are not descendants ' +
'of the form element', 'of the form element',