Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to import the testing library in Remix.
Remix
import { [1] } from '@remix-run/testing';
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'test' instead of 'render' to import from '@remix-run/testing'.
Importing 'useLoaderData' which is for data fetching, not testing.
✗ Incorrect
The 'render' function from '@remix-run/testing' is used to render components for testing in Remix.
2fill in blank
mediumComplete the code to write a simple test that checks if a component renders text.
Remix
test('renders welcome message', () => { const { getByText } = [1](<Welcome />); expect(getByText('Welcome')).toBeInTheDocument(); });
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'screen' directly without rendering the component first.
Using 'fireEvent' which is for simulating user actions, not rendering.
✗ Incorrect
The 'render' function is used to render the component so that we can query its output in tests.
3fill in blank
hardFix the error in the test by completing the missing assertion method.
Remix
expect(getByText('Loading')).[1]();
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'toBeNull' which checks for absence, not presence.
Using 'toBeUndefined' which is unrelated to DOM elements.
✗ Incorrect
The 'toBeVisible' matcher checks if the element is visible in the document, which is correct for testing loading states.
4fill in blank
hardFill both blanks to simulate a user clicking a button and then checking the updated text.
Remix
const { getByText } = render(<Counter />);
fireEvent.[1](getByText('Increment'));
expect(getByText('Count: [2]')).toBeInTheDocument(); Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'change' event which is for input fields, not buttons.
Expecting the count to be '2' after only one click.
✗ Incorrect
The 'click' event simulates a button press, and after one click, the count should update to '1'.
5fill in blank
hardFill all three blanks to write a test that waits for data to load and then checks the displayed result.
Remix
test('loads and displays data', async () => { const { findByText } = render(<DataFetcher />); const item = await findByText('[1]'); expect(item).toBeInTheDocument(); expect(item.textContent).toBe('[2]'); expect(typeof item.textContent).toBe('[3]'); });
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'number' as the type which is incorrect for text content.
Mismatching the text in findByText and expect.
✗ Incorrect
The test waits for the text 'Loaded Item' to appear, checks its content matches, and confirms the content is a string.