Bird
0
0

Why does this test fail?

medium📝 Debug Q7 of 15
Remix - Testing
Why does this test fail?
const { getByText } = render(<MyComponent />);
await waitFor(() => getByText('Loaded'));
AgetByText throws error if text not found immediately
BwaitFor cannot be used with getByText
Crender must be awaited
DwaitFor requires an async callback function
Step-by-Step Solution
Solution:
  1. Step 1: Understand getByText behavior inside waitFor

    getByText throws error if text not found immediately, causing waitFor to retry until timeout.
  2. Step 2: Confirm waitFor usage

    waitFor accepts sync or async callback; getByText throwing error is expected to retry.
  3. Final Answer:

    getByText throws error if text not found immediately -> Option A
  4. Quick Check:

    getByText throws error if no match, triggering waitFor retries [OK]
Quick Trick: getByText throws error if element missing, useful with waitFor [OK]
Common Mistakes:
MISTAKES
  • Thinking waitFor callback must be async
  • Expecting render to be awaited
  • Believing waitFor can't use getByText

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Remix Quizzes