arrow_backBACK TO DRILLS
Blue BeltuseeffectlockPREMIUM

waitFor and act Exist Because React State Updates Are Asynchronous

A test renders a component, fires a click that calls setState inside the handler, then immediately asserts on the resulting text.

REACT_MODULE // 0x42
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()?

lock

This Drill is Locked

This is a premium drill. Continue on to the next free drill in the sequence.

CONTINUE DRILLarrow_forward
BugDojo
BlogFAQ

© 2026. Carved in code.