arrow_backBACK TO DRILLS
Blue Belt - MediumuseeffectPREMIUM
Asserting Immediately After fireEvent without waitFor
A test renders a component, fires a click that calls setState inside the handler, then immediately asserts on the resulting text.
//REACT_MODULE
test('updates count on click', async () => {
render(<Counter />);
const button = screen.getByRole('button');
await fireEvent.click(button);
expect(screen.getByText('1')).toBeInTheDocument();
});Even though the click is awaited, why might this assertion fail intermittently unless wrapped in waitFor()?