Next.js Discord

Discord Forum

React and Next.js Testing

Unanswered
Dwarf Hotot posted this in #help-forum
Open in Discord
Dwarf HototOP
Hi guys, does anyone have a unit test experience on React? Which framework should we use it? Any recommendations? There is a lot of options to making testing scenario, I'm stuck there 😄

9 Replies

I am preparing a course on this topic, I've opened the waitlist : https://course.nextjspatterns.com/testing-qa-react-server-components-a-next-js-pattern
You'd want to use Jest or Vitest
The tricky part is mocking, the right pattern depends a lot on your components and architecture
But you could take a look at Mock Service Worker
These are common starting points for unit testing
There aren't much official recommendation for Next App Router, but you can treat RSCs as any other async functions
And client component as React components with the usual testing patterns
i recommend favouring visual approaches, like having a way to visualize your component during the unit test, if only for debugging
Storybook can be coupled with testing framework or you can use component testing features of Cypress