What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

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

Angular component harnesses give tests a supported, user-oriented way to operate a component without coupling assertions to its private HTML or CSS. They are most valuable for shared interactive components: tests can keep describing observable behavior even as the component’s internal markup changes.

What a component harness does

A component harness is a class that provides test code with methods for interacting with a component as a user would—for example, opening a menu or checking whether a control is enabled. Rather than querying internal elements and dispatching low-level events directly, a test calls the harness’s supported API. That makes the test less dependent on implementation details and lets the harness be reused across supported test environments. Angular’s harness guide and its CDK testing overview describe the approach.

Use a harness in a TestBed test

Harness infrastructure is provided by the Angular CDK. If the project does not already include it, add it with ng add @angular/cdk. Create the fixture, make a loader scoped to that fixture, then ask the loader for the harness. Harness methods are generally asynchronous, so await them.

const fixture = TestBed.createComponent(MyComponent);
const loader = TestbedHarnessEnvironment.loader(fixture);
const component = await loader.getHarness(MyComponentHarness);

await component.toggle();
expect(await component.isOpen()).toBe(true);

The exact harness class and methods depend on the component. The key pattern is to interact through the harness rather than reach into its private DOM.

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.

Choose the loader that can see the element

A fixture loader searches inside the fixture root. Some UI, including dialogs and other CDK overlays, is rendered elsewhere in the document, commonly beneath document.body. In that case, use a document-root loader:

const loader = TestbedHarnessEnvironment.documentRootLoader(fixture);
const dialog = await loader.getHarness(MyDialogHarness);

Use TestbedHarnessEnvironment.harnessForFixture when you want to load one harness directly for the fixture root. If a harness query unexpectedly finds nothing, first check whether the element is actually inside the loader’s search scope.

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.

Find the right harness instance

HarnessLoader supports several query patterns:

  • getHarness returns one matching harness.
  • getAllHarnesses returns all matches.
  • getHarnessAtIndex selects a match by index.
  • countHarnesses counts matches.
  • hasHarness checks whether a match exists.

When a component has multiple instances, prefer a meaningful filter over relying on their order. Harness classes commonly provide a static with() method that builds a HarnessPredicate, allowing tests to select an instance by a selector or component-specific text. The CDK overview documents harness predicates and loader queries.

Await interactions and control change detection when needed

Use await consistently for harness calls, including reads of component state. TestBed harnesses run change detection before reading element state and after interactions, which handles the usual case without manual fixture updates.

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.

For a test that must inspect an intermediate state while asynchronous work is still pending, use manualChangeDetection to control change detection for that block. Reserve it for cases where the timing itself matters; ordinary behavior tests can use the default automatic handling.

Write a custom harness around behavior

Extend ComponentHarness and define a static hostSelector that matches the component or directive selector. Expose actions and observable state, not a catalogue of internal elements. For instance, methods such as toggle() and isOpen() give tests a compact API tied to what the component does.

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

Use the harness locator methods—locatorFor, locatorForOptional, and locatorForAll—to resolve elements against the current DOM. This matters when conditional content disappears and is later recreated: locators avoid keeping stale element references. For interaction, use TestElement, the abstraction intended to work across environments, instead of directly manipulating raw DOM nodes.

For multiple component instances, a static with() method can expose a HarnessPredicate with common selectors or component-specific filters. Angular’s guide to creating component harnesses covers custom harness design and predicate use.

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.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Decide whether a component merits a harness

A custom harness adds an abstraction, so it is not necessary for every component. The strongest case is a shared component used in many places that has meaningful user interaction. Tests across the application can then rely on one supported API instead of repeating assumptions about the component’s internal structure.

A page used in only one place often gains less: its implementation and tests tend to change together. A harness may still be worthwhile if the same component needs a consistent test interface in unit and end-to-end suites. Angular’s authoring guidance makes the recommendation specifically for reusable, interactive shared components; it does not set a universal rule that every component needs a harness.

Built-in environments and adding another

The current Angular guide names TestBed unit tests and Selenium WebDriver end-to-end tests as built-in CDK harness environments. Harnesses can be adapted for other environments, but that requires environment-specific interaction support; check the documentation for the Angular and CDK versions used by your project, since supported environments can change.

A custom environment needs a TestElement implementation for its raw element type and a concrete HarnessEnvironment subclass. The implementation must provide ways to locate matching elements, create test elements and child environments, identify the document root, stabilize Angular work, and wait for tasks outside Angular. It should also provide a loader factory for test authors. These requirements make a new environment more than a selector adapter: it must reproduce the interaction and stabilization behavior harnesses rely on. See Angular’s custom harness environment documentation.

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

Match the example to your installed version

Angular’s documentation checked on October 5, 2026, reported documentation version v22.2.1+sha-ef03596. API names and supported test environments can evolve, so confirm examples against the Angular/CDK version installed in your project rather than assuming the newest guide exactly matches an older codebase. The CDK testing API reference is the reference point for the current API.

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.