Skip to content

Commit 3a4f978

Browse files
test: fix flaky test for modal wrapper (#22289)
* test: fix flaky test for modal wrapper * test: update with right assertions --------- Co-authored-by: Mahmoud <132728978+maradwan26@users.noreply.github.com>
1 parent 3d219df commit 3a4f978

1 file changed

Lines changed: 6 additions & 5 deletions

File tree

packages/react/src/components/ModalWrapper/ModalWrapper-test.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
*/
77

88
import React from 'react';
9-
import { render, screen } from '@testing-library/react';
9+
import { render, screen, waitFor } from '@testing-library/react';
1010
import userEvent from '@testing-library/user-event';
1111
import ModalWrapper from '../ModalWrapper';
1212

@@ -208,18 +208,19 @@ describe('ModalWrapper', () => {
208208
modalHeading="Modal heading"
209209
modalLabel="Label"
210210
handleSubmit={handleSubmit}
211+
shouldCloseAfterSubmit
211212
open>
212213
<p>Modal content here</p>
213214
</ModalWrapper>
214215
);
215216

216217
const triggerBtn = screen.getByText('Launch modal');
217218
const submitBtn = screen.getByText('Save');
218-
await userEvent.click(submitBtn);
219219

220+
await userEvent.click(triggerBtn);
221+
expect(submitBtn).toHaveFocus();
222+
await userEvent.click(submitBtn);
223+
expect(triggerBtn).toHaveFocus();
220224
expect(handleSubmit).toHaveBeenCalled();
221-
setTimeout(() => {
222-
expect(triggerBtn).toHaveFocus();
223-
}, 0);
224225
});
225226
});

0 commit comments

Comments
 (0)