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

For a new Angular CLI project, start with ng test: current Angular documentation describes Vitest as the default runner, with jsdom providing a browser-like DOM in Node.js. For most unit tests, this is the quicker path; use browser mode when real-browser APIs, rendering behavior, or browser debugging matter. Existing Karma projects remain supported, and Angular describes migration to Vitest as experimental.

Run Angular tests with the default setup

New Angular CLI projects are documented as ready to test with Vitest and jsdom. Vitest runs in Node.js; jsdom emulates the browser DOM so tests can exercise many component and application behaviors without launching a browser. Angular also names happy-dom as a supported alternative.

  1. Open a terminal at the Angular workspace root, where angular.json is located.
  2. Run ng test.
  3. In interactive use, the test target watches for file changes. In CI, set CI=true for non-interactive single-run behavior. If the CI environment does not set that variable, Angular documents ng test --no-watch --no-progress.

The test target can be configured in angular.json. Documented configuration areas include file patterns to include or exclude, setup files, provider files, coverage, browser selection, and a custom runner configuration. Angular handles most Vitest configuration. Treat a custom runner config as an advanced option: Angular does not support the contents of custom configuration files or third-party plugins.

Choose the test environment

Environment Useful for Trade-off
Node.js with jsdom or happy-dom Ordinary unit tests and fast feedback without launching a browser. A DOM emulator is not a real browser; browser-specific APIs and rendering may not behave identically.
Browser mode Tests that depend on browser-specific APIs, rendering behavior, or debugging in a browser. Requires installing a browser provider and selecting browser settings; it adds setup compared with the default Node-based route.

Angular documents Playwright and WebdriverIO providers for browser testing. Install the provider you choose and configure the test target’s browsers option. In CI, headless mode is used automatically when the CI environment variable is set; a browser name can also explicitly select headless mode. Choose browser mode for a concrete fidelity or debugging need rather than assuming it is always better.

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.

Test services with TestBed

TestBed creates an isolated Angular testing environment, configures dependency injection, and lets a test retrieve a service instance. Unless the test provides alternatives, dependencies are real, so the test can exercise the application’s actual service path.

import { TestBed } from '@angular/core/testing';
import { PriceService } from './price.service';

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

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

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

Replace PriceService with the service under test. Add providers or test doubles in the testing module when the test should isolate the service from a dependency; otherwise, TestBed uses the configured dependency injection graph.

Test component behavior and rendered output

A component combines a TypeScript class and an HTML template. TestBed can configure and create that combination. A fixture gives the test access to the component instance and rendered view; Angular’s DebugElement provides a platform-aware way to inspect elements and bindings.

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 { GreetingComponent } from './greeting.component';

describe('GreetingComponent', () => {
  it('renders the greeting', async () => {
    await TestBed.configureTestingModule({
      imports: [GreetingComponent],
    }).compileComponents();

    const fixture = TestBed.createComponent(GreetingComponent);
    fixture.detectChanges();

    expect(fixture.nativeElement.textContent).toContain('Hello');
  });
});

This example assumes GreetingComponent is standalone. For a non-standalone component, configure its declaring module or declaration as appropriate for the application. Direct nativeElement access assumes the active DOM implementation exposes the APIs the test uses. Prefer Angular’s DebugElement abstraction when portability across rendering environments matters.

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

Test HTTP behavior without a real backend

Angular’s @angular/common/http/testing utilities replace real network calls with a test backend. A test can make a request, inspect its URL or method, and flush a controlled response. The test 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 { DataService } from './data.service';

describe('DataService', () => {
  let service: DataService;
  let http: HttpTestingController;

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

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

  it('loads data from the API', () => {
    let result: unknown;
    service.load().subscribe(value => (result = value));

    const request = http.expectOne('/api/data');
    expect(request.request.method).toBe('GET');
    request.flush({ ok: true });

    expect(result).toEqual({ ok: true });
  });
});

Adapt the service method and expected endpoint to your code. The important test sequence is to trigger the application call, capture and assert the outgoing request, flush a controlled response, and verify outstanding requests.

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.

Measure coverage

For Vitest coverage, install @vitest/coverage-v8, then run:

ng test --coverage

Angular documents the generated report in the coverage/ directory. Coverage shows which code the tests exercise; a high percentage alone does not establish that assertions check the right behavior.

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.

Decide whether to keep Karma or migrate

Karma remains supported, and Angular documents Karma with Jasmine. A project’s existing setup does not become invalid merely because Vitest is the default for new CLI projects. Consider migration when the new runner and its workflow suit the project, but account for custom builder settings and legacy test patterns.

Rank #4
Sale
UGREEN USB to USB C Adapter Combo 4-Pack, 10Gbps USB C Converter Space Gray
  • Dual Converters, Infinite Potential:Includes 2× USB C male to USB A female adapters and 2× USB A male to USB C female adapters. Perfect for a wide range of uses—tablets with Bluetooth keyboards, expand USB ports on macbook, and more. Two different converters for all your daily needs
  • Next-Level 10Gbps & 3A Charging: No more slow 480Mbps, this usb to usb c adapter has a transfer speed of up to 10Gbps, allowing you to do more transferring in less time. This usb adapter fits both USB A and USB C charger, supporting up to 3A fast charging
  • Upgraded Exquisite Craftsmanship: With an aluminum alloy housing and metal connector, the usbc to usb adapter is extremely durable and sturdy. Rigorously tested to withstand more than 10,000 times of plugging and unplugging, ensuring long-lasting performance
  • Broad Compatible: The usb c to usb adapter widely supports all USB C/ USB A devices like laptops, tablets, cellphones, car chargers, and phone chargers. Such as compatible with MacBook Pro/Air 2023/2022, Thunderbolt 4/3 Devices,Apple MagSafe Watch 9/8/7/SE/Ultra, iPad Pro 2022/2021, Samsung Galaxy S23/S20/S10, and iPhone 17/16/15 Pro. Plug and play
  • Please Note: To reach 10Gbps speed, keep the cable under 3.3 ft. For USB A Male to USB C adapters, try flipping the USB C connector. USB C Male to USB A adapters support bidirectional 10Gbps transfer within 3.3 ft

What migration changes

Angular labels migration of an existing project to Vitest experimental. The documented migration requires the application build system, adds Vitest and a DOM emulator, and changes the test builder to @angular/build:unit-test. The new builder does not accept all old Karma builder options in the same place, so test-related build settings may need to move.

Audit and review the conversion

  • Inspect custom karma.conf.js behavior before removing or replacing it.
  • Review test-specific builder settings and move options where the new builder requires it.
  • The refactoring schematic can convert common Jasmine patterns, but it does not install dependencies, change the builder, move build options, or remove old files.
  • Complex or nested spy scenarios may not be converted correctly; review the schematic’s edits and run the suite.
  • Zone-based helpers can be patched, but plan to move toward native async code and Vitest fake timers where appropriate.

Do not treat the schematic as a complete migration. Run and inspect the test suite after each migration stage, especially where custom configuration or asynchronous timing is involved.

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

Troubleshoot common failures

  • The tests keep watching in CI. The environment may not set CI=true. Set it, or run ng test --no-watch --no-progress.
  • A test fails on a browser API. The selected DOM emulator may not implement the required API. Check whether the test needs a mock or should run in browser mode with an installed provider.
  • Rendered component output is empty or stale. Confirm the component is configured and compiled, create the fixture, and trigger change detection before asserting rendered output.
  • An HTTP test hangs or reports unmatched requests. Ensure the test captures and flushes each expected request, and use HttpTestingController.verify() to find requests left outstanding.
  • Migration builder options are rejected or ignored. Review the new unit-test builder configuration; not all former Karma builder options are accepted in the same location.
  • A migrated spy or timer test behaves differently. Review complex spy conversions manually and check whether legacy Zone-based timing should be replaced with native async patterns or Vitest fake timers.
  • Coverage cannot run. Confirm @vitest/coverage-v8 is installed before running ng test --coverage.

Or skip the browser setup

If you need a screenshot of a page produced by a running Angular application, ScreenshotNeo can return an image or PDF from a single request. This is separate from unit testing: use Angular’s test runner for assertions about application behavior, and a screenshot endpoint when you need a captured page.

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.

For API options, see the ScreenshotNeo documentation.

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

ScreenshotNeo accepts cookie or consent banners like a visitor and removes more than 60 known consent platforms, newsletter popups, and chat widgets before capture; those steps can be turned off. Bot checks, blank pages, timeouts, failed loads, and cache hits are not billed, and responses identify page verdict and billing status. Its MCP server provides take_screenshot, get_page_info, and capture_pdf tools for AI agents. The free plan includes 1,000 screenshots per month with no card; paid plans start at $5 for 3,000.

Sign up for ScreenshotNeo’s free plan to get 1,000 screenshots a month with no card.

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.

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