diff --git a/plugins/scaffolder/src/components/fields/RepoOwnerPicker/GitLabRepoOwnerPicker.test.tsx b/plugins/scaffolder/src/components/fields/RepoOwnerPicker/GitLabRepoOwnerPicker.test.tsx
index 7fb9ea21d6..fe60e1b376 100644
--- a/plugins/scaffolder/src/components/fields/RepoOwnerPicker/GitLabRepoOwnerPicker.test.tsx
+++ b/plugins/scaffolder/src/components/fields/RepoOwnerPicker/GitLabRepoOwnerPicker.test.tsx
@@ -91,34 +91,51 @@ describe('GitLabRepoOwnerPicker', () => {
});
it('should populate owners', async () => {
+ jest.useFakeTimers();
+ const user = userEvent.setup({
+ advanceTimers: jest.advanceTimersByTime,
+ });
const onChange = jest.fn();
- const { getByRole, getByText } = await renderInTestApp(
-
-
- ,
- );
+ try {
+ const { getByRole } = await renderInTestApp(
+
+
+ ,
+ );
- // Open the Autocomplete dropdown
- const input = getByRole('textbox');
- await userEvent.click(input);
+ // Open the Autocomplete dropdown
+ const input = getByRole('textbox');
+ await user.click(input);
- // Verify that the available owners are shown
- await waitFor(() => expect(getByText('owner1')).toBeInTheDocument());
+ // Flush the component debounce and any pending async updates
+ act(() => {
+ jest.advanceTimersByTime(500);
+ });
+ await act(async () => {
+ await Promise.resolve();
+ });
- // Verify that selecting an option calls onChange
- await userEvent.click(getByText('owner1'));
- expect(onChange).toHaveBeenCalledWith({
- owner: 'owner1',
- });
+ // Verify that the available owners are shown
+ expect(await screen.findByText('owner1')).toBeInTheDocument();
+
+ // Verify that selecting an option calls onChange
+ await user.click(screen.getByText('owner1'));
+ expect(onChange).toHaveBeenCalledWith({
+ owner: 'owner1',
+ });
+ } finally {
+ jest.runOnlyPendingTimers();
+ jest.useRealTimers();
+ }
});
it('should filter out excluded owners', async () => {