testing-library / testing-library/testing-library-docs

Document mocking best practices with nextjs

Open
#491 5 comments 5 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
JavaScript
Stars
479
Forks
740
PR merge metrics
No merged PRs in 30d

Description

I really like the change to recommend msw as the way to mock api requests however with nextjs there are some conventions that nextjs picks up on to make things happen server side. This is done by looking for a function called getServerSideProps (at least in the latest version). I am wondering if we can add some documentation to tell people the best way to mock this.

I think the best way to test these things is to test the getServerSideProps function seperately from the component on the page. This isn't exactly how the user would use the software as nextjs ties the two together and does the passing of the props to the component that is exported but it is close. If you can think of a better way I'd be interested in hearing ideas on this.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Review the existing MSW guidance and the Next.js getServerSideProps convention first. Document how to test getServerSideProps separately from the page component, or explain a better approach, with a clear recommendation for Next.js users.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, nextjs
Domain
documentation, testing
Issue type
Documentation
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.