本文へスキップ
製品デスクトップツール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製品情報は検証済みの開発ソースに基づいています。リリース・改善中

Angular ドキュメント
Angular
Getting Started with AngularProject StructureCore ConceptsData and StateTestingDeployment
ディスカッション

Angular ガイド · 5/6

Testing

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

Angular projects come with unit testing already configured, and the CLI can add an end-to-end (e2e) framework on request. This chapter covers running tests, testing components and services with TestBed, mocking HTTP, and browser-level e2e tests.

Running unit tests

Test files sit next to the code they test and end in .spec.ts. ng test runs them with the runner configured in the test target of angular.json:

ng test
ng test --watch=false
ng test --help

Which runner you get depends on when the project was created. Recent CLI versions set up Vitest for new projects, while projects created with older versions use Karma with the Jasmine framework in a real browser. Both use the same describe, it, beforeEach and expect structure, and Angular's TestBed works the same way in either, so the examples below run on both. Mocking helpers differ: Jasmine has jasmine.createSpy() and spyOn(), while Vitest has vi.fn() and vi.spyOn(). Options such as code coverage also depend on the runner; ng test --help lists what your project supports.

Testing a component

TestBed creates a small Angular environment for a test. Import the standalone component, create it, interact with the DOM and check the result. This test targets the Counter component from the core concepts chapter:

import { TestBed } from '@angular/core/testing';
import { Counter } from './counter';

describe('Counter', () => {
  beforeEach(async () => {
    await TestBed.configureTestingModule({ imports: [Counter] }).compileComponents();
  });

  it('starts at zero', () => {
    const fixture = TestBed.createComponent(Counter);
    fixture.detectChanges();
    expect(fixture.nativeElement.textContent).toContain('0 x 2 = 0');
  });

  it('increments when the button is clicked', () => {
    const fixture = TestBed.createComponent(Counter);
    fixture.detectChanges();

    const button: HTMLButtonElement = fixture.nativeElement.querySelector('button');
    button.click();
    fixture.detectChanges();

    expect(fixture.nativeElement.textContent).toContain('1 x 2 = 2');
  });
});

fixture.detectChanges() runs change detection so the DOM reflects the latest state. When a component waits for asynchronous work, await fixture.whenStable() waits until pending tasks have finished.

Replacing dependencies

To test a component in isolation, give it a fake version of a service through providers. Because inject() resolves through the same injector, the component receives the fake:

この章について質問がありますか?
前の章Data and State次の章Deployment
import { TestBed } from '@angular/core/testing';
import { signal } from '@angular/core';
import { HeroList } from './hero-list';
import { HeroService } from './hero.service';

it('renders heroes from the service', async () => {
  const fakeService = { all: signal([{ id: 1, name: 'Test Hero' }]), add: () => {} };

  await TestBed.configureTestingModule({
    imports: [HeroList],
    providers: [{ provide: HeroService, useValue: fakeService }],
  }).compileComponents();

  const fixture = TestBed.createComponent(HeroList);
  fixture.detectChanges();
  expect(fixture.nativeElement.textContent).toContain('Test Hero');
});

Testing HTTP calls

provideHttpClientTesting() swaps the real backend for HttpTestingController, which lets a test inspect outgoing requests and answer them. Register it after provideHttpClient():

import { TestBed } from '@angular/core/testing';
import { provideHttpClient } from '@angular/common/http';
import { HttpTestingController, provideHttpClientTesting } from '@angular/common/http/testing';
import { Todo, TodoApi } from './todo-api';

describe('TodoApi', () => {
  let api: TodoApi;
  let http: HttpTestingController;

  beforeEach(() => {
    TestBed.configureTestingModule({
      providers: [provideHttpClient(), provideHttpClientTesting()],
    });
    api = TestBed.inject(TodoApi);
    http = TestBed.inject(HttpTestingController);
  });

  afterEach(() => http.verify());

  it('requests a limited list', () => {
    let result: Todo[] = [];
    api.list(2).subscribe((todos) => (result = todos));

    const req = http.expectOne((r) => r.url.endsWith('/todos'));
    expect(req.request.method).toBe('GET');
    expect(req.request.params.get('_limit')).toBe('2');
    req.flush([{ id: 1, title: 'Write tests', completed: false }]);

    expect(result.length).toBe(1);
  });
});

http.verify() fails the test if any request was made but never answered.

End-to-end tests

New projects do not include an e2e framework. Running ng e2e in a project without an e2e target offers to add one; the choices include Playwright, Cypress, WebdriverIO, Nightwatch and Puppeteer. You can also install a tool directly. With Playwright:

npm init playwright@latest
npx playwright test

Point Playwright at the dev server in playwright.config.ts so it starts the app before the tests:

import { defineConfig } from '@playwright/test';

export default defineConfig({
  use: { baseURL: 'http://localhost:4200' },
  webServer: {
    command: 'npm start',
    url: 'http://localhost:4200',
    reuseExistingServer: !process.env['CI'],
  },
});
import { expect, test } from '@playwright/test';

test('home page greets the user', async ({ page }) => {
  await page.goto('/');
  await expect(page.getByRole('heading', { level: 1 })).toContainText('Hello');
});

Summary

  • ng test runs .spec.ts files with the project's configured runner: Vitest in recent projects, Karma and Jasmine in older ones.
  • TestBed creates components and services; detectChanges() updates the DOM.
  • Swap dependencies with providers and test HTTP with provideHttpClientTesting().
  • Add an e2e tool such as Playwright or Cypress through ng e2e or by installing it directly.

コメント 0件

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

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