Unit tests check small pieces of code, integration tests check how components and data work together, and end-to-end tests simulate browser behavior. Robinson recommends tests that resemble real user actions and prioritizing high-value flows, such as login or payment, over pursuing full unit-test coverage without considering the effort.
Testing & Error Handling
Lee Robinson, a developer at Vercel (then Zeit), explains testing and error handling for Next.js in the Learn Next.js course.
Robinson describes Jest as the test runner and React Testing Library as a way to query rendered DOM in a user-oriented way. He demonstrates setting up a shared render helper with Chakra providers, then testing a bar card's text, image, and deal-count badge. He advises using snapshots cautiously, since large snapshots can be hard to review and easy to accept without inspection.
The sign-in example checks a critical path by entering credentials, submitting the form, and verifying the result. The tests mock the authentication hook and router, then check successful sign-in and navigation, an API error displayed to the user, and validation messages when fields are blank. Robinson recommends limiting mocks while testing user-visible behavior.
Robinson recommends exception monitoring such as Sentry to catch errors in production and lower environments, noting that Next.js apps need to account for both server-side and client-side errors. He shows how a custom `_error` page can present different experiences for errors such as 404s and 500s, and suggests checking Next.js's Sentry plugin and examples for setup.
Takeaways
- Prioritize tests for high-value user flows, such as sign-in and payment.
- Query elements by visible text, labels, roles, or alt text before resorting to test IDs.
- Use snapshots selectively and keep them small enough for reviewers to understand.
- Mock external dependencies at a deliberate boundary, then verify both outcomes and visible errors.
- Add exception monitoring and tailor error pages to help users recover or navigate away.
Mentioned in this talk
Search inside this talk
What was claimed 5
- integrates with
Testing Library integrates with Jest
“a set of helpful methods on top of Jest”
YouTube Unverified1 source· Talk
- integrates with
Next.js integrates with
Testing Library
“There are quite a few examples with Next.js as well, because it's designed to pair well with React.”
YouTube Unverified1 source· Talk
- uses
“Jest can pick up and understand how to compile the code based on our Next.js application's configuration.”
YouTube Unverified1 source· Talk
- feature
Sentry MCP: Exception monitoring
“Sentry is a SaaS solution for exception monitoring”
YouTube Unverified1 source· Talk
- feature
Next.js: Customizable error page through the _error page
“we can override the page that's _error”
YouTube Unverified1 source· Talk





