Bird
0
0

Which of the following is the correct syntax to define a mock response with msw in Remix?

easy📝 Syntax Q3 of 15
Remix - Testing
Which of the following is the correct syntax to define a mock response with msw in Remix?
Aserver.handle('/api/data', () => { return { key: 'value' } })
Bfetch('/api/data').mockReturnValue({ key: 'value' })
Cmock('/api/data').returns({ key: 'value' })
Drest.get('/api/data', (req, res, ctx) => res(ctx.json({ key: 'value' })))
Step-by-Step Solution
Solution:
  1. Step 1: Recall msw syntax for mocking GET requests

    msw uses rest.get with a handler function returning res(ctx.json(...)) for JSON responses.
  2. Step 2: Compare other options

    Other options use incorrect or non-msw syntax for mocking.
  3. Final Answer:

    rest.get('/api/data', (req, res, ctx) => res(ctx.json({ key: 'value' }))) -> Option D
  4. Quick Check:

    msw syntax = rest.get + res(ctx.json) [OK]
Quick Trick: msw uses rest.get with res(ctx.json(...)) for mocks [OK]
Common Mistakes:
MISTAKES
  • Using fetch.mockReturnValue which is not msw
  • Wrong method names like mock or server.handle

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Remix Quizzes