Next.js Discord

Discord Forum

App vs pages router; testability

Unanswered
Giant panda posted this in #help-forum
Open in Discord
Giant pandaOP
Hi, I have to build a new Next.js enterprise app and would like to use something like Cypress component tests for unit testing, while being able to mock api requests nicely (in the Cypress case with    cy.intercept(<url>, <mock response>) ). I read that async server components are not supported for that, neither in vitest. So a few questions:

1. What is the best way to test apps that use async server components? Do I always need e2e tests for that in addition to unit tests?
2. If I simply don't use async server components in app router, will the app be fully compatible with Cypress component tests?
3. If we are not using async server components, would it be easier and better to use the pages router? I read that it is more stable, and has client side rendering by default.

5 Replies

Greek Shepherd
Idk anything about cypress but if its making u consider throwing away 50% of ur frameworks features just to test a component ur either using the wrong framework or the wrong testing tool
I do know that playwright works with async components tho
Giant pandaOP
Playwright is an e2e tool, isn't it?
@Giant panda Playwright is an e2e tool, isn't it?
Greek Shepherd
Sry im thinking of jest
Giant pandaOP
What I don't like about Jest is that it does not render the components so that you can see them. With cypress component tests, you always see what is happening and you can develop the visual as well as functional parts of your apps in one go