Consider this Remix component tested with Testing Library. What will be the visible text after clicking the button?
import { useState } from 'react'; export default function Counter() { const [count, setCount] = useState(0); return ( <> <p>Count: {count}</p> <button onClick={() => setCount(count + 1)}>Increment</button> </> ); }
Think about what happens when the button's onClick handler runs.
Clicking the button calls setCount with count + 1, increasing count from 0 to 1, so the text updates to 'Count: 1'.
In a Remix integration test, which query correctly selects the button with the text 'Submit'?
Buttons have a role of 'button' and accessible name is the visible text.
getByRole with role 'button' and name matching 'Submit' correctly finds the button. getByText does not take a name option. getByLabelText is for form labels. queryByPlaceholderText is for input placeholders.
Given this test snippet, what text will be visible after the form submission completes?
import { render, screen, fireEvent, waitFor } from '@testing-library/react'; import ContactForm from '~/components/ContactForm'; render(<ContactForm />); fireEvent.change(screen.getByLabelText(/email/i), { target: { value: 'user@example.com' } }); fireEvent.click(screen.getByRole('button', { name: /send/i })); await waitFor(() => screen.getByText(/thank you/i));
Think about what the form shows after successful submission.
The test waits for the text containing 'thank you', which appears after successful submission, so the final visible text is 'Thank you for contacting us!'.
Review this test code snippet. Why does it fail with a timeout waiting for the success message?
import { render, screen, fireEvent } from '@testing-library/react'; import Login from '~/components/Login'; render(<Login />); fireEvent.click(screen.getByRole('button', { name: /login/i })); screen.getByText(/welcome back/i);
Think about how Testing Library handles async UI updates.
The success message appears asynchronously after clicking login, so the test must wait (e.g., with waitFor or findByText). Without waiting, getByText throws a timeout error.
When writing integration tests for Remix apps, which approach best supports accessibility testing?
Accessibility means using roles and names that assistive tech relies on.
Using getByRole with accessible names mimics how users with assistive technologies interact with the UI, ensuring tests reflect real accessibility. Selecting by class or test IDs does not guarantee accessibility. getByText alone may miss semantic roles.