A React Testing Library integration test misses an async boundary, causing a false pass or flaky failure.
Codejavascript
import { render, screen } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import UserProfile from './UserProfile';
test('loads and displays the user name after fetch', () => {
render(<UserProfile userId="42" />);
// Click the button that triggers the async fetch
userEvent.click(screen.getByRole('button', { name: /load/i }));
// Assert the fetched name is shown
expect(screen.getByText('Ada Lovelace')).toBeInTheDocument();
});
This integration test is unreliable. What is the bug and how should it be fixed?