medium10 pts · first answer countsreact-testing-librarytesting
Test fails before data arrives
A component fetches users after mount (mocked in the test). This assertion fails with "Unable to find an element", but the app works in the browser. What is the fix?
render(<UserList />)
expect(screen.getByText('Ana')).toBeInTheDocument()Discussion 0
Join free to post in the discussion.
Related questions
- Finding a button in a testFrontend Developer
- Asserting an error is goneFrontend Developer
- userEvent versus fireEventFrontend Developer
- Testing text that appears after a fetchFrontend Developer
- The "not wrapped in act" warningFrontend Developer
- Mocking APIs in component testsFrontend Developer
- Naming a test that uses a real DBBackend Developer
- Testing code that calls a payment APIBackend Developer