Challenge - 5 Problems
Remix Loader & Action Testing Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ component_behavior
intermediate1:30remaining
What does this loader return?
Given this Remix loader function, what will be the JSON response when called?
Remix
import { json } from '@remix-run/node'; export async function loader() { return json({ message: 'Hello from loader', count: 3 }); }
Attempts:
2 left
💡 Hint
Look carefully at the keys and value types in the returned JSON.
✗ Incorrect
The loader returns a JSON response with keys exactly as defined: 'message' and 'count' with count as a number 3.
❓ state_output
intermediate1:30remaining
What is the action's returned status code?
Consider this Remix action function. What HTTP status code will the response have?
Remix
import { json } from '@remix-run/node'; export async function action({ request }) { const formData = await request.formData(); const name = formData.get('name'); if (!name) { return json({ error: 'Name required' }, { status: 400 }); } return json({ success: true }); }
Attempts:
2 left
💡 Hint
Check the condition for returning status 400 carefully.
✗ Incorrect
If 'name' is missing, status 400 is returned. Otherwise, the default status 200 is used.
🔧 Debug
advanced2:00remaining
Why does this loader test fail?
This test for a Remix loader fails. What is the cause?
Remix
import { loader } from './route'; test('loader returns correct message', async () => { const response = await loader(); const data = await response.json(); expect(data.message).toBe('Hello from loader'); });
Attempts:
2 left
💡 Hint
Think about what loader() returns and how to extract JSON from it.
✗ Incorrect
Remix loaders return a Response object. To get JSON, you must call response.json() which returns a promise.
📝 Syntax
advanced1:30remaining
Which action code snippet correctly handles form data?
Select the code snippet that correctly extracts 'email' from form data in a Remix action.
Attempts:
2 left
💡 Hint
Remember that formData() returns a promise and you must await it.
✗ Incorrect
request.formData() returns a promise, so you must await it before calling get(). Option C does this correctly.
🧠 Conceptual
expert2:30remaining
What is the best way to unit test a Remix loader that depends on session data?
You have a Remix loader that reads user info from a session cookie. Which approach correctly isolates the loader for unit testing?
Attempts:
2 left
💡 Hint
Think about how to isolate external dependencies in unit tests.
✗ Incorrect
Unit tests should isolate external dependencies. Mocking session retrieval and passing a fake request allows testing loader logic without real sessions.