@testing-library/angular Simple and complete Angular testing utilities that encourage good testing practices. Read The Docs | Edit the docs <!-- prettier-ignore-start --> [![Build Status][build-badge]][build] [![version][version-badge]][package] [![downloads][downloads-badge]][npmtrends] [![MIT License][license-badge]][license] [![PRs Welcome][prs-badge]][prs]…
@testing-library/angular
Simple and complete Angular testing utilities that encourage good testing
practices.
<!-- prettier-ignore-start -->
[![Build Status][build-badge]][build]
[![version][version-badge]][package] [![downloads][downloads-badge]][npmtrends]
[![MIT License][license-badge]][license]

[![PRs Welcome][prs-badge]][prs] [![Code of Conduct][coc-badge]][coc]
[![Discord][discord-badge]][discord]
[![Watch on GitHub][github-watch-badge]][github-watch]
[![Star on GitHub][github-star-badge]][github-star]
[![Tweet][twitter-badge]][twitter]
<!-- prettier-ignore-end -->

Table of Contents
<!-- START doctoc generated TOC please keep comment here to allow auto update -->
<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->
- [Table of Contents](#table-of-contents)
- [The problem](#the-problem)
- [This solution](#this-solution)
- [Example](#example)
- [Installation](#installation)
- [Version compatibility](#version-compatibility)
- [Guiding Principles](#guiding-principles)
- [Contributors](#contributors)
- [Docs](#docs)
- [FAQ](#faq)
jest-dom matcher toHaveFormValues always returns an empty object or there are missing fields. Why?](#i-am-using-reactive-forms-and-the-jest-dom-matcher-tohaveformvalues-always-returns-an-empty-object-or-there-are-missing-fields-why)
- [Issues](#issues)
- [Getting started with GitHub Codespaces](#getting-started-with-github-codespaces)
- [LICENSE](#license)
The problem
You want to write maintainable tests for your Angular components. As a part of
this goal, you want your tests to avoid including implementation details of your
components and rather focus on making your tests give you the confidence for
which they are intended. As part of this, you want your testbase to be
maintainable in the long run so refactors of your components (changes to
implementation but not functionality) don't break your tests and slow you and
your team down.
This solution
The @testing-library/angular is a very lightweight solution for
testing Angular components. It provides light utility functions on top of Angular
and @testing-library/dom, in a way that encourages better testing practices. Its
primary guiding principle is:
> [The more your tests resemble the way your software is used, the more
> confidence they can give you.][guiding-principle]
Example
counter.component.ts
ts
@Component({
selector: 'atl-counter',
template: `
{{ hello() }}
-
Current Count: {{ counter() }}
+
`,
})
export class CounterComponent {
counter = model(0);
hello = input('Hi', { alias: 'greeting' });
increment() {
this.counter.set(this.counter() + 1);
}
decrement() {
this.counter.set(this.counter() - 1);
}
}
counter.component.spec.ts
typescript
import { render, screen, fireEvent, aliasedInput } from '@testing-library/angular';
import { CounterComponent } from './counter.component';
describe('Counter', () => {
it('should render counter', async () => {
await render(CounterComponent, {
inputs: {
counter: 5,
// aliases need to be specified this way
...aliasedInput('greeting', 'Hello Alias!'),
},
});
expect(screen.getByText('Current Count: 5')).toBeVisible();
expect(screen.getByText('Hello Alias!')).toBeVisible();
});
it('should increment the counter on click', async () => {
await render(CounterComponent, { inputs: { counter: 5 } });
const incrementButton = screen.getByRole('button', { name: '+' });
fireEvent.click(incrementButton);
expect(screen.getByText('Current Count: 6')).toBeVisible();
});
});
Installation
This module is distributed via [npm][npm] which is bundled with [node][node] and
should be installed as one of your project's devDependencies.
Starting from ATL version 17, you also need to install @testing-library/dom:
bash
npm install --save-dev @testing-library/angular @testing-library/dom
Or, you can use the ng add command.
This sets up your project to use Angular Testing Library, which also includes the installation of @testing-library/dom.
bash
ng add @testing-library/angular
You may also be interested in installing jest-dom so you can use
the custom jest matchers.
> Docs
Version compatibility
| Angular | Angular Testing Library |
| ------- | ---------------------------------- |
| 22.x | 19.x |
| 21.x | 19.x |
| 20.x | 18.x, 17.x, 16.x, 15.x, 14.x, 13.x |
| 19.x | 17.x, 16.x, 15.x, 14.x, 13.x |
| 18.x | 17.x, 16.x, 15.x, 14.x, 13.x |
| 17.x | 17.x, 16.x, 15.x, 14.x, 13.x |
| 16.x | 14.x, 13.x |
| >= 15.1 | 14.x, 13.x |
| < 15.1 | 12.x, 11.x |
| 14.x | 12.x, 11.x |
Guiding Principles
> [The more your tests resemble the way your software is used, the more
> confidence they can give you.][guiding-principle]
We try to only expose methods and utilities that encourage you to write tests
that closely resemble how your Angular components are used.
Utilities are included in this project based on the following guiding
principles:
1. If it relates to rendering components, it deals with DOM nodes rather than
component instances, nor should it encourage dealing with component
instances.
2. It should be generally useful for testing individual Angular components or
full Angular applications.
3. Utility implementations and APIs should be simple and flexible.
At the end of the day, what we want is for this library to be pretty
light-weight, simple, and understandable.
Contributors
Thanks goes to these people ([emoji key][emojis]):
<!-- ALL-CONTRIBUTORS-LIST:START - Do not remove or modify this section -->
<!-- prettier-ignore-start -->
<!-- markdownlint-disable -->
Tim Deschryver💻 📖 🚇 ⚠️
Michaël De Boey📖
Ignacio Le Fluk💻 ⚠️
Tamás Szabó💻
Gregor Woiwode💻
Toni Villena🐛 💻 📖 ⚠️
ShPelles📖
Miluoshi💻 ⚠️
Nick McCurdy📖
Srinivasan Sekar📖
Bitcollage📖
Emil Sundin💻
Ombrax💻
Rafael Santana💻 ⚠️ 🐛
Benjamin Blackwood📖 ⚠️
Gustavo Porto📖
Bo Vandersteene💻
Janek💻 ⚠️
Gleb Irovich💻 <a href="https://github.com/testing-library/angular-testing-library/commits?author=G
…
Members
-
react-testing-library ★ PINNED
🐐 Simple and complete React DOM testing utilities that encourage good testing practices.
JavaScript ★ 20k 3mo agoExplain → -
dom-testing-library ★ PINNED
🐙 Simple and complete DOM testing utilities that encourage good testing practices.
JavaScript ★ 3.3k 8mo agoExplain → -
testing-library-docs ★ PINNED
docs site for @testing-library/*
JavaScript ★ 480 1d agoExplain → -
jest-dom ★ PINNED
:owl: Custom jest matchers to test the state of the DOM
JavaScript ★ 4.6k 1mo agoExplain → -
user-event ★ PINNED
🐕 Simulate user events
TypeScript ★ 2.3k 10mo agoExplain → -
react-hooks-testing-library ★ PINNED
🐏 Simple and complete React hooks testing utilities that encourage good testing practices.
TypeScript ★ 5.3k 2y agoExplain → -
cypress-testing-library
🐅 Simple and complete custom Cypress commands and utilities that encourage good testing practices.
JavaScript ★ 1.8k 2mo agoExplain → -
vue-testing-library
🦎 Simple and complete Vue.js testing utilities that encourage good testing practices.
JavaScript ★ 1.1k 2y agoExplain → -
eslint-plugin-testing-library
ESLint plugin to follow best practices and anticipate common mistakes when writing tests with Testing Library
TypeScript ★ 1.1k 7h agoExplain → -
testing-playground
Simple and complete DOM testing playground that encourage good testing practices.
JavaScript ★ 814 10mo agoExplain → -
angular-testing-library
🐙 Simple and complete Angular testing utilities that encourage good testing practices
TypeScript ★ 789 24d agoExplain → -
svelte-testing-library
:chipmunk: Simple and complete Svelte DOM testing utilities that encourage good testing practices
JavaScript ★ 662 15d agoExplain → -
native-testing-library ▣
🐳 Simple and complete React Native testing utilities that encourage good testing practices.
JavaScript ★ 516 6y agoExplain → -
jest-native
🦅 Custom jest matchers to test the state of React Native
TypeScript ★ 439 1y agoExplain → -
eslint-plugin-jest-dom
eslint rules for use with jest-dom
JavaScript ★ 367 5mo agoExplain → -
pptr-testing-library
puppeteer + dom-testing-library = 💖
TypeScript ★ 290 2y agoExplain → -
playwright-testing-library ▣
🔍 Find elements in Playwright with queries from Testing Library
TypeScript ★ 252 11mo agoExplain → -
preact-testing-library
Simple and complete Preact DOM testing utilities that encourage good testing practices.
JavaScript ★ 158 4mo agoExplain → -
testing-library-recorder-extension
Testing Library Extension for Chrome DevTools Recorder
TypeScript ★ 153 3y agoExplain → -
which-query ▣
🦩 Which query should I use?
CSS ★ 122 5y agoExplain → -
react-render-stream-testing-library
A library to make commited-render-to-committed-render assertions on your React components and hooks.
TypeScript ★ 103 8mo agoExplain → -
testcafe-testing-library
:ox: Simple and complete custom Selectors for Testcafe that encourage good testing practices.
TypeScript ★ 69 2y agoExplain → -
preact-hooks-testing-library
Simple and complete Preact hooks testing utilities that encourage good testing practices.
TypeScript ★ 58 4y agoExplain → -
jasmine-dom
🦥 Custom Jasmine matchers to test the state of the DOM
JavaScript ★ 47 1y agoExplain → -
nightwatch-testing-library
🦇Simple and complete custom queries for Nightwatch that encourage good testing practices.
JavaScript ★ 29 3y agoExplain → -
webdriverio-testing-library
🕷️ Simple and complete WebdriverIO DOM testing utilities that encourage good testing practices.
TypeScript ★ 18 3y agoExplain → -
dom-testing-library-template
Template repository for bug reports to @testing-library/dom, @testing-library/react, and @testing-library/jest-dom
JavaScript ★ 16 5y agoExplain → -
native-testing-library-docs ▣
🐳 Docs site for native-testing-library
JavaScript ★ 13 6y agoExplain → -
react-testing-library-help
Fork this repo to reproduce your issue
HTML ★ 11 3y agoExplain → -
web-testing-library
🐙 Experimental Web testing utilities that encourage good testing practices.
JavaScript ★ 7 2y agoExplain → -
.github
No description.
★ 0 3y agoExplain →
No repos match these filters.