Choose one: Hardware, Software, Coding, Game, or Windows⏱️ 2 min read📅 2026-06-03

How to Fix: How to solve the "update was not wrapped in act()" warning in testing-library-react?

SEO meta description 140-155 characters.

Quick Answer: 1-2 sentences of direct conversational advice.

To solve the "update was not wrapped in act()" warning, you need to wrap your component updates in act or use renderWithinElement from @testing-library/react. Here are some examples:

Method 1: Wrapping with act

Using act:

  1. Step 1: Import act from @testing-library/react.
  2. Step 2: Wrap your component update with act(() => { /* your component code here */ }).

Method 2: Using renderWithinElement

Using renderWithinElement:

  1. Step 1: Import renderWithinElement from @testing-library/react.
  2. Step 2: Wrap your component update with renderWithinElement(, () => { /* your component code here */ }).

Method 3: Using waitForElement

Using waitForElement:

  1. Step 1: Import waitForElement from @testing-library/react.
  2. Step 2: Use waitForElement() to wait for your component to update.

✨ Wrapping Up

By following these methods, you can resolve the "update was not wrapped in act()" warning and write more reliable tests for your React components.

Did this fix your problem?

If not, try searching for specific error codes.

🔍 Search Error Database

❓ Frequently Asked Questions