mirror of
https://github.com/zebrajr/react.git
synced 2025-12-06 12:20:20 +01:00
Add test for multiple form submissions (#33059)
Test for #30041 and #33055
This commit is contained in:
parent
edf550b679
commit
79586c7eb6
|
|
@ -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',
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user