Bird
0
0

In a unit test for an action, this code snippet is used:

medium📝 Predict Output Q5 of 15
Remix - Testing
In a unit test for an action, this code snippet is used:
const request = new Request('http://localhost', {
  method: 'POST',
  body: new URLSearchParams({ name: 'Alice' })
});

const response = await action({ request });
const data = await response.json();

What will data contain if the action returns json({ success: true })?
AA Response object
B{ success: true }
CUndefined
DAn error thrown
Step-by-Step Solution
Solution:
  1. Step 1: Understand action return type

    The action returns a Response object created by json({ success: true }).
  2. Step 2: Extract JSON from Response

    Calling response.json() parses the Response body and returns the original object.
  3. Final Answer:

    { success: true } -> Option B
  4. Quick Check:

    response.json() returns original JSON data [OK]
Quick Trick: Call response.json() to get JSON data from action response [OK]
Common Mistakes:
MISTAKES
  • Expecting Response object instead of parsed data
  • Not awaiting response.json()
  • Confusing request body with response data

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Remix Quizzes