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

デスクトップツール

TASTECAD複雑な図面を、軽やかにひらくTASTEFILES必要なファイルだけを、最速でTASTEFTPファイルが行き交う、いちばん端正な道TASTESSHサーバーとあなたを、より確かにつなぐTASTEZIPより速くまとめ、より安全にひらくTASTEWINM2つの画面で整理する、キーボード中心のファイルマネージャー

開発ツール

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

サーバー

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

投資

TASTESTOCKいつ・何を。自分で決めたルールどおりに動く株式自動売買

はじめる

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

ニュース

今日の開発ニュース言語・フレームワーク・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ツールの問題ショーケース
ポリシー会社概要プライバシーポリシー利用規約サブスクリプション規約返金ポリシーコミュニティガイドライン
アカウントログイン新規登録
訪問者
今日
昨日
累計閲覧
商号
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製品情報は検証済みの開発ソースに基づいています。リリース・改善中

React ドキュメント
React
Getting Started with ReactProject StructureCore ConceptsData and StateTestingBuild and Deployment
ディスカッション

React ガイド · 5/6

Testing

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

Tests for a React app usually come in two layers. Components and hooks are checked quickly with Vitest and React Testing Library, while complete user flows run in a real browser with Playwright.

Installing Vitest and React Testing Library

Vitest reuses your Vite configuration, so it needs almost no extra transform setup. Install it together with jsdom, which emulates the browser DOM, and the Testing Library packages.

npm install -D vitest jsdom @testing-library/react @testing-library/dom @testing-library/user-event @testing-library/jest-dom

Add a test section to vite.config.ts. The reference comment at the top lets TypeScript know about the test field.

/// <reference types="vitest/config" />
import { defineConfig } from "vite";
import react from "@vitejs/plugin-react";

export default defineConfig({
  plugins: [react()],
  test: {
    environment: "jsdom",
    globals: true,
    setupFiles: "./src/test/setup.ts",
    include: ["src/**/*.test.{ts,tsx}"],
  },
});

With globals: true, Testing Library automatically cleans up rendered output after each test. Setting include keeps Vitest from picking up the Playwright tests you will add later. The setup file src/test/setup.ts registers DOM-specific matchers such as toBeInTheDocument().

import "@testing-library/jest-dom/vitest";

Finally, add "test": "vitest" to the scripts in package.json. npm test runs in watch mode and re-runs related tests on every save; in CI, run once with npx vitest run.

Testing components

Testing Library steers you toward testing what the user sees rather than implementation details. Find elements by accessible information such as getByRole or getByLabelText whenever possible, and simulate clicks and typing with user-event, which mimics real user interaction closely.

// src/Counter.tsx
import { useState } from "react";

export function Counter() {
  const [count, setCount] = useState(0);
  return <button onClick={() => setCount(count + 1)}>Clicked {count} times</button>;
}
// src/Counter.test.tsx
import { render, screen } from "@testing-library/react";
import userEvent from "@testing-library/user-event";
import { describe, expect, it } from "vitest";
import { Counter } from "./Counter";

describe("Counter", () => {
  it("increments when clicked", async () => {
    const user = userEvent.setup();
    render(<Counter />);

    const button = screen.getByRole("button", { name: "Clicked 0 times" });
    await user.click(button);

    expect(button).toHaveTextContent("Clicked 1 times");
  });
});

Async UI and mocks

Components that load data should receive mocked responses instead of hitting the network. Replace the global fetch with vi.spyOn, and use findBy... queries, which wait for elements that appear later. The UserName component from the previous chapter serves as the example.

import { render, screen } from "@testing-library/react";
import { afterEach, expect, it, vi } from "vitest";
import { UserName } from "./UserName";

afterEach(() => {
  vi.restoreAllMocks();
});

it("loads and shows the user's name", async () => {
  vi.spyOn(globalThis, "fetch").mockResolvedValue(
    new Response(JSON.stringify({ id: 1, name: "Ada" })),
  );

  render(<UserName userId={1} />);

  expect(screen.getByText("Loading…")).toBeInTheDocument();
  expect(await screen.findByText("Ada")).toBeInTheDocument();
});

For apps with many API calls, Mock Service Worker (MSW) intercepts requests at the network level, so tests and the dev server can share the same mock API.

Testing custom hooks

To test a hook without any UI, use renderHook. Wrap calls that update state in act so React applies every update before you assert on the result.

import { act, renderHook } from "@testing-library/react";
import { expect, it } from "vitest";
import { useTodos } from "./useTodos";

it("adds a todo", () => {
  const { result } = renderHook(() => useTodos());

  act(() => result.current.add("Buy milk"));

  expect(result.current.todos).toHaveLength(1);
  expect(result.current.todos[0].text).toBe("Buy milk");
});

End-to-end tests with Playwright

Playwright launches real Chromium, Firefox and WebKit browsers and drives your app the way a user would. The init command creates the config file and an example test, and installs the browsers in one go.

npm init playwright@latest

Setting webServer in playwright.config.ts starts the dev server automatically before the tests run.

import { defineConfig, devices } from "@playwright/test";

export default defineConfig({
  testDir: "./e2e",
  use: { baseURL: "http://localhost:5173" },
  webServer: {
    command: "npm run dev",
    url: "http://localhost:5173",
    reuseExistingServer: !process.env.CI,
  },
  projects: [{ name: "chromium", use: { ...devices["Desktop Chrome"] } }],
});
// e2e/counter.spec.ts (assumes the home page renders Counter)
import { expect, test } from "@playwright/test";

test("the counter button works", async ({ page }) => {
  await page.goto("/");
  await page.getByRole("button", { name: /Clicked/ }).click();
  await expect(page.getByRole("button", { name: "Clicked 1 times" })).toBeVisible();
});

Run the suite with npx playwright test; add --ui to step through each action with a live view while debugging. Playwright's expect retries until the condition holds, so there is no need for arbitrary sleeps.

Summary

  • Test components and hooks with Vitest and React Testing Library, and full browser flows with Playwright.
  • Find elements by role and label, and simulate interaction with user-event.
  • Wait for async results with findBy... queries, and mock the network with vi.spyOn or MSW.
  • Playwright's webServer option starts the dev server automatically for end-to-end runs.
この章について質問がありますか?
前の章Data and State次の章Build and Deployment

コメント 0件

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

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