本文へスキップ
製品デスクトップツールTASTECAD図面の確認TASTEFILESファイル管理TASTEFTPファイル転送TASTESSHリモートワークスペースTASTEZIP圧縮と展開開発ツールTASTECODERust 統合開発環境TASTESTUDIO統合開発・テスト環境TASTEETLデータ統合(ETL)サーバーTASTEREMOTEリモートデスクトップサーバーTASTEGEO空間情報サーバーTASTEMAILメールワークスペースはじめるダウンロードドキュメント購入すべての製品
マーケットプレイス
ニュース
技術ニュース今日の開発ニュース開発ドキュメントプログラミング言語RustTypeScriptJavaScriptPythonGoC#JavaCC++KotlinDartWebフロントエンド フレームワークNext.jsReactVue.js · NuxtSvelteKitAngularサーバー フレームワークSpring BootDjangoFastAPIASP.NET CoreNestJS · Expressアプリ・デスクトップ フレームワークTauriFlutterReact NativeElectronアルゴリズムアルゴリズムの基礎主要アルゴリズム発展アルゴリズム実務のアルゴリズム
コミュニティプロジェクト開発ログプロンプトAIツールの問題ショーケースコミュニティガイド
協業技術移転ウェブサイト構築デスクトップアプリ構築リリース・決済パイプライン販売パートナーお問い合わせ
サービスリモートデスクトップインストールパッケージのカスタマイズ
TASTEDEV
製品

デスクトップツール

TASTECAD複雑な図面を、軽やかにひらくTASTEFILES必要なファイルだけを、最速でTASTEFTPファイルが行き交う、いちばん端正な道TASTESSHサーバーとあなたを、より確かにつなぐTASTEZIPより速くまとめ、より安全にひらく

開発ツール

TASTECODERust アプリの編集・ビルド・デバッグ・テストまでひとつのウィンドウでTASTESTUDIO編集からリモートテスト、承認した AI 修正までTASTEETL値を見ながら、データを運ぶ

サーバー

TASTEREMOTE自社サーバーで運用するリモートデスクトップTASTEGEOGeoServer 互換の空間情報サーバーを Rust で作り直しますTASTEMAILメールの主導権を、もう一度自分の手に

はじめる

ダウンロード全製品の最新版ドキュメント各製品の使い方購入サブスクリプション・永久ライセンスすべての製品全製品を一覧で
すべての製品
マーケットプレイスニュース
技術

ニュース

今日の開発ニュース言語・フレームワーク・GitHub・AI の公式発表開発ドキュメント言語・フレームワーク・アルゴリズムのガイド

プログラミング言語

RustTypeScriptJavaScriptPythonGoC#JavaCC++KotlinDart

フレームワーク

Webフロントエンド フレームワークNext.jsReactVue.js · NuxtSvelteKitAngular
サーバー フレームワークSpring BootDjangoFastAPIASP.NET CoreNestJS · Express
アプリ・デスクトップ フレームワークTauriFlutterReact NativeElectron

アルゴリズム

アルゴリズムの基礎計算量解析 · ソート · 探索 · 基本データ構造 · 木構造とヒープ主要アルゴリズムグラフ探索 · 最短経路と最小全域木 · 動的計画法 · 貪欲法 · 分割統治法 · バックトラッキング発展アルゴリズム文字列アルゴリズム · 数学と整数論 · ビット演算 · セグメント木 · Union-Find実務のアルゴリズムコーディング面接対策 · LRUキャッシュ · レート制限 · コンシステントハッシュ法
開発ドキュメントをすべて見る
コミュニティ
プロジェクトビルダーと作品を探す開発ログ決定と試行錯誤プロンプト再利用できる指示AIツールの問題Claude・Codex・Gemini の問題と回避策ショーケース完成した成果コミュニティガイドオープンにつくる方法
協業
技術移転Rust・egui でネイティブアプリを作るウェブサイト構築10言語、アカウント、ドキュメントとダウンロードデスクトップアプリ構築Rust・egui、WebView なしリリース・決済パイプライン署名・MSI・deb・rpm・AppImage・ハッシュ販売パートナー紹介して決済額の30%お問い合わせ構築・提携・投資のご相談
サービス
リモートデスクトップブラウザから自分のパソコンへインストールパッケージのカスタマイズ必要な機能だけ、設定は事前に
購入
JA
한국어EnglishDeutschEspañolFrançaisItalianoPortuguês (Brasil)日本語简体中文繁體中文
ログイン
ログイン
TASTEDEV

小さなツールから、より良い開発へ。

support@tastedev.netTASTEDEVを支援
製品製品ラインナップ購入ドキュメントダウンロードマーケットプレイスサポート
コミュニティプロジェクト開発ログプロンプトAIツールの問題ショーケース
ポリシープライバシーポリシー利用規約サブスクリプション規約返金ポリシーコミュニティガイドライン
アカウントログイン新規登録
訪問者
今日
012345678901234567890123456789012345678901234567890123456789
昨日
012345678901234567890123456789012345678901234567890123456789
累計閲覧
0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789
商号
GXSOFT
代表者
CHOI YOUNG GU
事業者登録番号
853-44-00368
所在地
9F V24, 351 Gyeongin-ro, Michuhol-gu, Incheon, Republic of Korea
電話
+82-10-4404-1523
メール
whitecalvin@tastedev.net
個人情報保護責任者
CHOI YOUNG GU

© 2026 TASTEDEV製品情報は検証済みの開発ソースに基づいています。リリース・改善中

Next.js ドキュメント
Next.js
Getting Started with Next.jsProject StructureCore ConceptsData and StateTestingDeployment
ディスカッション

Next.js ガイド · 5/6

Testing

この章は現在、英語でのみ提供しています。

Next.js applications are usually tested on two levels. Unit tests check individual components and functions quickly, typically with Vitest or Jest plus React Testing Library. End-to-end (E2E) tests open pages in a real browser and walk through user flows, typically with Playwright or Cypress. This chapter focuses on setting up and writing tests with Vitest and Playwright.

What to test with which tool

TargetRecommended toolsWhy
Pure functions, validation, data transformsVitest or JestFast, no browser needed
Client Components, synchronous Server ComponentsVitest or Jest with React Testing LibraryChecks rendered output and interactions
async Server Components, routing, Server Action flowsPlaywright or CypressExercises the real server and browser

async Server Components are relatively new to the React ecosystem, and unit test runners such as Vitest and Jest cannot fully render them yet. The official docs therefore recommend covering them with E2E tests. If you extract the data-processing logic from such a component into plain functions, you can still unit test that part thoroughly.

Setting up Vitest

Install the packages as dev dependencies. vite-tsconfig-paths lets your tests resolve aliases such as @/.

npm install -D vitest @vitejs/plugin-react jsdom @testing-library/react @testing-library/dom vite-tsconfig-paths

Create a config file at the project root and add a "test": "vitest" script to package.json.

// vitest.config.mts
import { defineConfig } from "vitest/config";
import react from "@vitejs/plugin-react";
import tsconfigPaths from "vite-tsconfig-paths";

export default defineConfig({
  plugins: [tsconfigPaths(), react()],
  test: {
    environment: "jsdom",
  },
});

You can also start from an official example such as create-next-app --example with-vitest, which comes with this setup in place. If you prefer Jest, the next/jest helper configures SWC transforms, CSS and image imports, and environment variable loading for you.

Testing components

Render a Client Component such as the LikeButton from the previous chapter, click it like a user would, and assert on the result. React Testing Library encourages you to query by role and visible text rather than implementation details.

// app/ui/like-button.test.tsx
import { describe, expect, it } from "vitest";
import { fireEvent, render, screen } from "@testing-library/react";
import { LikeButton } from "./like-button";

describe("LikeButton", () => {
  it("increments the count on each click", () => {
    render(<LikeButton initial={3} />);
    const button = screen.getByRole("button");
    fireEvent.click(button);
    expect(button.textContent).toContain("4");
  });
});

Components that call next/navigation hooks such as useRouter or usePathname need a mock, because the Next.js router does not exist in the test environment.

import { vi } from "vitest";

vi.mock("next/navigation", () => ({
  useRouter: () => ({ push: vi.fn(), refresh: vi.fn() }),
  usePathname: () => "/dashboard",
  useSearchParams: () => new URLSearchParams("q=next"),
}));

E2E tests with Playwright

Playwright automates Chromium, Firefox and WebKit through one API. Its setup wizard creates a config file and example tests.

npm init playwright

With the webServer option, Playwright starts your Next.js server before the tests and waits until it is ready. For results closer to production, test a production build served by next start rather than the dev server.

// playwright.config.ts
import { defineConfig } from "@playwright/test";

export default defineConfig({
  testDir: "./e2e",
  use: { baseURL: "http://localhost:3000" },
  webServer: {
    command: "npm run build && npm run start",
    url: "http://localhost:3000",
    reuseExistingServer: !process.env.CI,
  },
});
// e2e/navigation.spec.ts
import { expect, test } from "@playwright/test";

test("navigates from the home page to About", async ({ page }) => {
  await page.goto("/");
  await page.getByRole("link", { name: "About" }).click();
  await expect(page).toHaveURL("/about");
  await expect(page.getByRole("heading", { level: 1 })).toHaveText("About");
});

Run E2E tests with npx playwright test, or use npx playwright test --ui to step through each run visually. Flows that involve Server Actions, such as form submissions, are best verified this way, under realistic conditions.

Running tests in CI

A typical CI pipeline runs linting, type checking, unit tests, the build and then E2E tests. You can type-check separately with npx tsc --noEmit, and next build also reports type errors. Putting the fast steps first surfaces failures early.

Summary

  • Unit test pure logic and Client Components with Vitest (or Jest) and React Testing Library.
  • Cover async Server Components and full user flows with an E2E tool such as Playwright.
  • Mock next/navigation hooks in unit tests.
  • Run E2E tests against a server started with next start after next build for production-like results.
この章について質問がありますか?
前の章Data and State次の章Deployment

コメント 0件

人気のコメント順新しい順

ログイン · ログインするとコメントできます。