DriversRecommendedOutdated drivers can make a good PC feel brokenScan driver issues before chasing fixes manually.Scan NowOctober DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsClean PCRecommendedOne scan can reveal what keeps slowing WindowsLook for cleanup and repair opportunities.Run Scan×
Skip to content
World desk7 min

Angular Testing: A Practical Guide

New Angular CLI projects run Vitest with ng test. Learn the practical patterns for service, component, and HTTP tests, plus coverage, CI, browser mode, and Karma migration trade-offs.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

New Angular CLI projects use Vitest by default: run ng test to start. Existing Karma projects remain supported, but moving them to Vitest is documented as experimental. For most unit tests, Angular’s Node.js and DOM-emulation setup is the faster starting point; use browser mode when the behavior depends on a real browser. Angular’s testing overview explains the current options.

Run Angular tests with the default setup

The Angular CLI includes Vitest and jsdom for new CLI projects. Vitest runs in Node.js, while jsdom supplies a browser-like DOM without launching a browser. Angular also documents happy-dom as an alternative DOM emulator.

  1. Open a terminal at the Angular workspace root, where angular.json is located.

  2. Run ng test. In interactive use, the test target watches files and reruns tests when they change.

    Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
    #1 Best Overall
    Elebase USB to USB C Adapter for iPhone 18 Pro Max,USBC Car Charger Adapter
    • Read Before You Buy — No Video Output: These adapters support charging and USB 2.0 data transfer, but cannot transmit video signals. Except for standard USB webcams (which use USB data only), they are not compatible with HDMI/DisplayPort cables, video-capable USB-C hubs, or docking stations with video output.
    • Convert USB-A Ports to USB-C: Designed to connect USB-C earphones, cables, flash drives, card readers, and other USB-C accessories to standard USB-A ports. Plug-and-play with no drivers or software required.
    • Aluminum Alloy Housing: Built with a sturdy aluminum alloy shell that aids in heat dissipation and protects against daily wear and scratches. Designed to maintain a stable and secure connection.
    • Compact & Travel-Friendly: The ultra-compact design allows the adapter to stay plugged into your device without blocking adjacent ports or adding bulk, reducing wear and tear on your original USB ports.
    • 12-Month Warranty: Backed by a 12-month manufacturer warranty for peace of mind. Designed to meet strict quality control standards for reliable everyday performance.
  3. Read the test results in the terminal. If you need to debug browser-dependent behavior, configure browser mode as described below.

The exact test builder and options depend on the project configuration. Angular’s CLI manages most Vitest setup; the test target in angular.json can configure include and exclude patterns, setup files, provider files, coverage, browser selection, and a custom runner configuration. Custom runner configuration is an advanced route: Angular does not support the contents of custom configuration files or third-party plugins.

Run tests in CI

When the environment sets CI=true, Angular switches to non-interactive, single-run behavior. If your CI system does not set that variable, use ng test --no-watch --no-progress to avoid watch mode and progress output.

Choose between DOM emulation and a real browser

DOM emulation is a good default when tests exercise application logic and ordinary component behavior. It avoids starting a browser, which Angular describes as faster for most unit tests. It may not reproduce every browser API or rendering detail, however.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Approach Useful when Trade-off
Node.js with jsdom or happy-dom Most unit tests and fast feedback are the priority. Browser behavior is emulated, not supplied by a real browser.
Browser mode Tests depend on browser-specific APIs or rendering, or you need to debug in a browser. Requires installing and configuring a browser provider and browser; startup adds setup and execution work.

Angular documents Playwright and WebdriverIO providers. Install the provider you choose and configure the test target’s browsers option. In CI, browser mode uses headless operation automatically when the CI environment variable is set; you can also select a browser name that explicitly chooses headless mode. Check the current provider documentation for supported browsers and setup details before relying on a particular browser or version.

Test services with TestBed

A service test can use TestBed to create an isolated Angular testing environment, configure dependency injection, and retrieve the service under test. Unless you override a dependency, the test uses the real dependency registered in the test configuration. That can be useful for checking the actual application code path, but replace dependencies when you need a focused unit test or want to avoid external effects.

Rank #2
Anker USB-C Hub, 5-in-1 USB Hub for Laptops, 4K HDMI Multiport Adapter
  • 5-in-1 USB-C Hub: Experience comprehensive connectivity featuring a Power Delivery input, two USB-A 2.0 ports, a USB-A 3.0 port, and an HDMI port. (Note: The USB-C power delivery input port is only for connecting an external wall charger to power your laptop and cannot power peripheral devices.)
  • 90W Pass-Through Charging: Achieve optimal charging with 90W pass-through power to your laptop, supported by a total input of 100W, with the hub reserving 10W for operational efficiency. (Note: Wall charger not included.)
  • Quick Data Transfers: Accelerate your productivity with rapid data transfers using a high-speed 5Gbps USB 3.0 port and two 480Mbps USB 2.0 ports.
  • 4K HDMI Display: Enhance your visual experience with a hub capable of delivering 4K resolution at 30Hz in both mirror and extend modes. Please note that this hub is compatible with MacBook (macOS 12 and newer), Windows 10 and 11, ChromeOS, and laptops equipped with DP Alt Mode and Power Delivery. Note: This device is not compatible with Linux.
  • What You Get: Anker USB-C Hub (5-in-1, 4K HDMI), welcome guide, 18-month warranty, and our friendly customer service.
import { TestBed } from '@angular/core/testing';
import { MyService } from './my.service';

describe('MyService', () => {
  let service: MyService;

  beforeEach(() => {
    TestBed.configureTestingModule({});
    service = TestBed.inject(MyService);
  });

  it('creates the service', () => {
    expect(service).toBeTruthy();
  });
});

Replace MyService with the service and imports in your project. Add providers or test doubles to configureTestingModule when the service needs dependencies that you want to control.

Test components through their rendered behavior

A component combines a TypeScript class and an HTML template. Configure the component in TestBed, create a fixture, trigger change detection, and inspect the rendered result. A fixture gives access to the component instance and its rendered view; Angular’s DebugElement provides a platform-aware way to query and interact with that view.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
import { TestBed } from '@angular/core/testing';
import { MyComponent } from './my.component';

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

  it('renders the component', () => {
    const fixture = TestBed.createComponent(MyComponent);
    fixture.detectChanges();

    expect(fixture.componentInstance).toBeTruthy();
    expect(fixture.debugElement).toBeTruthy();
  });
});

This is a starting pattern, not a complete assertion for every component. Add expectations for the user-visible behavior the test is intended to protect, such as text, state changes, or event handling. Accessing nativeElement assumes the active DOM implementation exposes the APIs your test uses. Prefer Angular’s abstractions where they provide the behavior you need, especially if tests should work across environments.

Test HTTP requests without calling the backend

Angular’s @angular/common/http/testing package lets tests capture outgoing requests, assert their properties, and flush controlled responses. The test backend replaces real network access; tests must flush expected requests and verify that no unexpected requests remain.

import { provideHttpClient } from '@angular/common/http';
import {
  HttpTestingController,
  provideHttpClientTesting,
} from '@angular/common/http/testing';
import { TestBed } from '@angular/core/testing';
import { MyService } from './my.service';

describe('MyService HTTP behavior', () => {
  let service: MyService;
  let httpTesting: HttpTestingController;

  beforeEach(() => {
    TestBed.configureTestingModule({
      providers: [
        provideHttpClient(),
        provideHttpClientTesting(),
        MyService,
      ],
    });
    service = TestBed.inject(MyService);
    httpTesting = TestBed.inject(HttpTestingController);
  });

  afterEach(() => {
    httpTesting.verify();
  });

  it('requests data and handles the response', () => {
    service.getData().subscribe((data) => {
      expect(data).toEqual({ value: 'example' });
    });

    const request = httpTesting.expectOne('/api/data');
    expect(request.request.method).toBe('GET');
    request.flush({ value: 'example' });
  });
});

Adapt the service method, expected URL, and response shape to your application. If a test does not make the request it expects, it cannot flush that request; if it makes an unanticipated request, the verification step helps expose it.

Measure coverage without mistaking it for quality

For Vitest coverage, install @vitest/coverage-v8 using the package manager used by your project, then run ng test --coverage. Angular documents the resulting report in the coverage/ directory. You can also enable coverage in the test target configuration.

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Rank #3
Sale
Anker USB C Hub, 7in1 Multi-Port USB Adapter, 4K@60Hz USBC to HDMI Splitter
  • Sleek 7-in-1 USB-C Hub: Features an HDMI port, two USB-A 3.0 ports, and a USB-C data port, each providing 5Gbps transfer speeds. It also includes a USB-C PD input port for charging up to 100W and dual SD and TF card slots, all in a compact design.
  • Flawless 4K@60Hz Video with HDMI: Delivers exceptional clarity and smoothness with its 4K@60Hz HDMI port, making it ideal for high-definition presentations and entertainment. (Note: Only the HDMI port supports video projection; the USB-C port is for data transfer only.)
  • Double Up on Efficiency: The two USB-A 3.0 ports and a USB-C port support a fast 5Gbps data rate, significantly boosting your transfer speeds and improving productivity.
  • Fast and Reliable 85W Charging: Offers high-capacity, speedy charging for laptops up to 85W, so you spend less time tethered to an outlet and more time being productive.
  • What You Get: Anker USB-C Hub (7-in-1), welcome guide, 18-month warranty, and our friendly customer service.

Coverage shows which code was exercised; a high percentage does not establish that tests check meaningful behavior. Use the report to find untested areas, then decide whether additional assertions would protect important outcomes.

Keep or migrate an existing Karma project?

Karma remains supported, and Angular maintains a guide for Karma with Jasmine. A project does not need to migrate just because new CLI projects now use Vitest. Consider migration when the benefits justify reviewing the test builder, project-specific settings, and test patterns.

Angular explicitly describes migration of an existing project to Vitest as experimental. The migration guide requires the application build system. It adds Vitest and a DOM emulator, changes the test builder to @angular/build:unit-test, and may require moving test-specific build settings because the new builder does not accept all old Karma builder options in the same place.

Migration checks

For project-specific steps, follow Angular’s Vitest migration guide alongside its testing overview. Because the migration is experimental, validate the instructions against the Angular documentation and the builder configuration used by your project.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Troubleshoot common test failures

  • ng test is not recognized: Run it from the workspace root and confirm the Angular CLI is available to the project. Check that the workspace defines a test target in angular.json.

  • Tests keep running or CI hangs: Interactive mode watches files. Set CI=true, or use ng test --no-watch --no-progress where CI does not provide that variable.

  • A DOM or browser API is missing: The default environment emulates the DOM, so it may not provide the browser-specific behavior your test needs. Use a supported browser provider for tests that require browser APIs or rendering fidelity.

    Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
    Best Value
    Anker USB C Hub, 5-in-1 USBC to HDMI Splitter with 4K Display
    • 5-in-1 Connectivity: Equipped with a 4K HDMI port, a 5 Gbps USB-C data port, two 5 Gbps USB-A ports, and a USB C 100W PD-IN port. Note: The USB C 100W PD-IN port supports only charging and does not support data transfer devices such as headphones or speakers.
    • Powerful Pass-Through Charging: Supports up to 85W pass-through charging so you can power up your laptop while you use the hub. Note: Pass-through charging requires a charger (not included). Note: To achieve full power for iPad, we recommend using a 45W wall charger.
    • Transfer Files in Seconds: Move files to and from your laptop at speeds of up to 5 Gbps via the USB-C and USB-A data ports. Note: The USB C 5Gbps Data port does not support video output.
    • HD Display: Connect to the HDMI port to stream or mirror content to an external monitor in resolutions of up to 4K@30Hz. Note: The USB-C ports do not support video output.
    • What You Get: Anker 332 USB-C Hub (5-in-1), welcome guide, our worry-free 18-month warranty, and friendly customer service.
  • An HTTP test waits indefinitely or fails verification: Check that the test made the expected request, flush its response, and verify there are no outstanding requests. The test backend does not call the real service endpoint.

  • Migration produces builder or configuration errors: Confirm the project uses the application build system, inspect the new unit-test builder options, and move or remove settings that belonged only to the Karma builder. Review custom Karma configuration before cleanup.

  • A migrated spy or asynchronous test behaves differently: The schematic does not cover every complex spy pattern. Inspect transformed tests, simplify nested spy setups where possible, and plan replacement of Zone-based helpers with native async patterns or Vitest fake timers.

  • Coverage does not run: Confirm @vitest/coverage-v8 is installed, then run ng test --coverage.

    Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Or skip the browser setup

If what you need is a screenshot of a website as part of a workflow, an API can replace browser automation for the capture itself. ScreenshotNeo’s one-call endpoint returns an image or PDF, with options documented at the ScreenshotNeo API documentation.

curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://stripe.com -o shot.webp

ScreenshotNeo accepts cookie and consent banners like a visitor and removes more than 60 known consent platforms, newsletter popups, and chat widgets before capture; each step can be turned off. Bot checks, blank pages, timeouts, failed loads, and cache hits are not billed, and the response identifies the page verdict and billing status in headers. Its MCP server provides screenshot tools for Claude, Cursor, and other MCP clients. The free plan includes 1,000 screenshots a month with no card; paid plans start at $5 for 3,000 shots.

Sign up for ScreenshotNeo’s free plan.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More from the Wire

  1. Shenzhen desk3 min
    HONOR Expands Beyond Smartphones With Humanoid Robot RevealHONOR said it unveiled its first humanoid robot at MWC 2026 and named shopping assistance, workplace inspections, and supportive companionship as intended uses. Later Robotics D1 claims and a reported…
  2. Cupertino desk5 min
    Apple Unveils AirPods Max 2: The Upgrade That Should Have Happened Years AgoAirPods Max 2 adds H2-powered audio features and Apple claims up to 1.5× more effective ANC, but its design, Smart Case, and 20-hour battery rating are unchanged. Wired lossless audio…
  3. Cupertino desk4 min
    Apple’s OLED Touch MacBooks Are Coming—but the Dynamic Island Is the Real GambleApple has not announced an OLED touchscreen MacBook, but reports point to high-end models arriving in late 2026 or early 2027. The reported Mac Dynamic Island could be useful, but…
Recommended PC Tool
Recommended PC Tool
Crashes, No Sound, or Screen Glitches?Free driver scan
Windows Errors? Fix Them Before They SpreadFree repair scan

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.