Next.js Discord

Discord Forum

Testing in Next.js

Answered
Chinese Alligator posted this in #help-forum
Open in Discord
Avatar
Chinese AlligatorOP
What is the industry practice for testing in Next.js, currently i'm employing jest but what are the other approaches or tools that can be considered.
Answered by Eric Burel
the difficulty with Next is that some features are super imbricated into a kind of hidden context, like the "headers()" function, but normally you should be able to mock them with Jest when needed
View full answer

6 Replies

Avatar
Spot-breasted Oriole
Haven’t had any problems with Jest and Playwright. I hear people like Vitest too but not sure how well it plays in a predominately Next environment.
Avatar
I see this question come up often but it's really not very mature
I'd say whatever works
I tend to prefer end to end testing for Next.js, and Jest is fine for unit testing and allows mocking
Avatar
the difficulty with Next is that some features are super imbricated into a kind of hidden context, like the "headers()" function, but normally you should be able to mock them with Jest when needed
Answer
Avatar
Spot-breasted Oriole
+1. Also we use chromatic and storybook for visual regression testing at my org and that’s worked well and replaced a lot of basic component unit tests.