Course map
Stage 1: App Router Foundations
Stage 2: The Rendering Model
Stage 3: Data, Caching and Mutations
Stage 4: Full-Stack Next.js
Stage 5: Production and Specialization

Part 17 / Topic 7 of 8

Honestly flagged: Vitest cannot unit-test an async Server Component

The installed docs say this plainly, in a callout, not buried: "Since async Server Components are new to the React ecosystem, Vitest currently does not support them. While you can still run unit tests for synchronous Server and Client Components, we recommend using E2E tests for async components." This part does not take that on faith — it reproduces the real failure (examples/05-async-server-component-probe.tsx), a scratch file created, run once, and deleted, never added to this harness's committed suite:

$ npm run test -- app/mandi/async-probe.test.tsx
stdout | BODY: <div></div>
stderr | <AsyncGreeting> is an async Client Component. Only Server Components can be async at the moment. ...
stderr | A component suspended inside an `act` scope, but the `act` call was not awaited. ...
FAIL: AssertionError: expected null to be truthy

Every real page in this course — every page.tsx, every CartContents-style inner component that calls await getCartId() or await requireUser() — has exactly this async function Component() shape, for exactly the reasons Parts 8–16 taught (Server Components read data by awaiting it directly, no useEffect, no loading-state dance). That means none of QuickCart's actual page-level Server Components are unit-testable with this toolchain, full stop — not "hard," not "needs a workaround," genuinely unsupported by Vitest as of this install. The honest options, neither attempted in this course:

  • E2E tests (Playwright, the installed docs' own named alternative) drive a real browser against a real running server, so the async Server Component actually executes server-side exactly as it does in production — no unit-test gap to work around at all.
  • Push logic out of the async component and into a plain function (exactly section 4's shape) that the component then calls — the function is unit-testable the normal way, and the remaining async component shrinks to "fetch, then render," which is cheap to verify by hand or cover with the E2E layer above.

No Playwright project was installed or run while writing this part — this section states the documented limit and reproduces the unit-test failure for real, but the E2E alternative itself is unverified here, same honesty rule TOOLING.md and the track briefs use for anything not actually run.

Done here? The practice set for Part 17 — including the solutions — is on the part page.

Search the guide