CLI

test

Command
ng test [project] [options]
ng t [project] [options]

Takes the name of the project, as specified in the projects section of the angular.json workspace configuration file. When a project name is not supplied, it will execute for all projects.

Builders

This command has the following builders

Arguments

project

The name of the project to run the command for. Can be an application or a library.

Value Typestring

Options

configuration
Aliasc

One or more named builder configurations as a comma-separated list as specified in the "configurations" section in angular.json. The builder uses the named configurations to run the given target. For more information, see https://angular.dev/reference/configs/workspace-config#alternate-build-configurations.

Value Typestring
help

Shows a help message for this command in the console.

Value Typeboolean

Unit-test builder options

browser-viewport

Specifies the browser viewport dimensions for browser-based tests in the format widthxheight.

Value Typestring
browsers

Specifies the browsers to use for test execution. When not specified, the Vitest runner runs tests in a Node.js environment using happy-dom if it is installed, otherwise jsdom, and the Karma runner uses the browsers of its configuration. Browser names ending with Headless enable headless mode (e.g., ChromiumHeadless for Vitest with the Playwright provider, or ChromeHeadless for Karma).

Value Typearray
build-target

Specifies the build target to use for the unit test build in the format project:target[:configuration]. This defaults to the build target of the current project with the development configuration. You can also pass a comma-separated list of configurations. Example: project:target:production,staging.

Value Typestring
coverage

Enables coverage reporting for tests. If not specified, the coverage configuration from a runner configuration file will be used if present. Otherwise, coverage is disabled by default.

Value Typeboolean
coverage-exclude

Specifies glob patterns of files to exclude from the coverage report.

Value Typearray
coverage-include

Specifies glob patterns of files to include in the coverage report.

Value Typearray
coverage-reporters

Specifies the reporters to use for coverage results. Each reporter can be a string representing its name, or a tuple containing the name and an options object. Built-in reporters include 'html', 'lcov', 'lcovonly', 'text', 'text-summary', 'cobertura', 'json', and 'json-summary'.

Value TypearrayAllowed Valuescobertura, html, json, json-summary, lcov, lcovonly, text, text-summary
debug

Enables debugging mode for tests, allowing the use of the Node Inspector.

Value TypebooleanDefaultfalse
exclude

Specifies glob patterns of files to exclude from testing, relative to the project source root.

Value Typearray
filter

Specifies a regular expression pattern to match against test suite and test names. Only tests with a name matching the pattern will be executed. For example, ^App will run only tests in suites beginning with 'App'.

Value Typestring
headless

Forces all configured browsers to run in headless mode. When using the Vitest runner, this option is ignored if no browsers are configured. The Karma runner does not support this option.

Value Typeboolean
include

Specifies glob patterns of files to include for testing, relative to the project source root. This option also has special handling for directory paths (includes all test files within) and file paths (includes the corresponding test file if one exists).

Value TypearrayDefault**/*.spec.ts,**/*.test.ts
isolate

Enables isolation for test execution. When true, Vitest runs tests in separate threads or processes. This option is only available for the Vitest runner. Defaults to false to align with the Karma/Jasmine experience.

Value Typeboolean
list-tests

Lists all discovered test files and exits the process without building or executing the tests.

Value TypebooleanDefaultfalse
output-file

Specifies a file path for the test report. This path is used by every configured reporter that writes to a file. To write a separate file for each reporter, use the tuple format ['reporter-name', { outputFile: '...' }] within the reporters option. When not provided, output is written to the console.

Value Typestring
polyfills

A list of polyfills to include in the build. Can be a full path for a file, relative to the current workspace or module specifier. Example: 'zone.js'. If not specified, polyfills will be inherited from the build target.

Value Typearray
progress

Shows build progress information in the console. Defaults to the progress setting of the specified buildTarget.

Value Typeboolean
providers-file

Specifies the path to a TypeScript file that provides an array of Angular providers for the test environment. The file must contain a default export of the provider array.

Value Typestring
quiet

Suppresses the verbose build summary and stats table on each rebuild. Defaults to true locally and false in CI environments.

Value Typeboolean
reporters

Specifies the reporters to use during test execution. Each reporter can be a string representing its name, or a tuple containing the name and an options object. Built-in reporters include 'default', 'verbose', 'dots', 'json', 'junit', 'tap', 'tap-flat', and 'html'. You can also provide a path to a custom reporter.

Value Typearray
runner

Specifies the test runner to use for test execution.

Value TypestringAllowed Valueskarma, vitestDefaultvitest
runner-config

Specifies the configuration file for the selected test runner. If a string is provided, it will be used as the path to the configuration file. If true, the builder will search for a default configuration file (e.g., vitest-base.config.mts or karma.conf.js). If false, no external configuration file will be used.\nFor Vitest, this enables advanced options and the use of custom plugins. Please note that while the file is loaded, the Angular team does not provide direct support for its specific contents or any third-party plugins used within it.

Value Typestring
setup-files

A list of paths to global setup files that are executed before the test files. The application's polyfills and the Angular TestBed are always initialized before these files.

Value Typearray
splitting

Enables code splitting for test execution. When enabled, shared code between test files is split into separate chunks. Issues with live ESM bindings in Node.js environments (such as uninitialized exports or mocking failures) can be resolved by disabling splitting. This option is only available for the Vitest runner.

Value TypebooleanDefaulttrue
ts-config

The path to the TypeScript configuration file, relative to the workspace root. Defaults to tsconfig.spec.json in the project root if it exists. If not specified and the default does not exist, the tsConfig from the specified buildTarget will be used.

Value Typestring
ui

Enables the Vitest UI for interactive test execution. This option is only available for the Vitest runner.

Value Typeboolean
watch

Enables watch mode, which re-runs tests when source files change. Defaults to true in TTY environments and false otherwise.

Value Typeboolean

Karma builder options

aot

Run tests using Ahead of Time compilation.

Value TypebooleanDefaultfalse
browsers

Override which browsers tests are run against. Set to false to not use any browser.

Value Typestring
code-coverage

Output a code coverage report.

Value TypebooleanDefaultfalse
code-coverage-exclude

Globs to exclude from code coverage.

Value Typearray
define

Defines global identifiers that will be replaced with a specified constant value when found in any JavaScript or TypeScript code including libraries. The value will be used directly. String values must be put in quotes. Identifiers within Angular metadata such as Component Decorators will not be replaced.

Value Typearray
exclude

Globs of files to exclude, relative to the project source root.

Value Typearray
external-dependencies

Exclude the listed external dependencies from being bundled into the bundle. Instead, the created bundle relies on these dependencies to be available during runtime.

Value Typearray
include

Globs of files to include, relative to the project source root. There are 2 special cases:

  • when a path to a directory is provided, all test files ending ".@(spec|test).@(ts|tsx)" will be included
  • when a path to a file is provided, and a matching test file exists, it will be included instead.
Value TypearrayDefault**/*.spec.ts
inline-style-language

The stylesheet language to use for the application's inline component styles.

Value TypestringAllowed Valuescss, less, sass, scssDefaultcss
karma-config

The name of the Karma configuration file.

Value Typestring
main

The name of the main entry-point file.

Value Typestring
poll

Enable and define the file watching poll time period in milliseconds.

Value Typenumber
polyfills

A list of polyfills to include in the build. Can be a full path for a file, relative to the current workspace or module specifier. Example: 'zone.js'.

Value Typearray
preserve-symlinks

Do not use the real path when resolving modules. If unset then will default to true if NodeJS option --preserve-symlinks is set.

Value Typeboolean
progress

Log progress to the console while building.

Value TypebooleanDefaulttrue
reporters

Karma reporters to use. Directly passed to the karma runner.

Value Typearray
scripts

Global scripts to be included in the build.

Value Typearray
source-map

Output source maps for scripts and styles. For more information, see https://angular.dev/reference/configs/workspace-config#source-map-configuration.

Value TypebooleanDefaulttrue
styles

Global styles to be included in the build.

Value Typearray
ts-config

The name of the TypeScript configuration file.

Value Typestring
watch

Re-run tests when source files change.

Value TypebooleanDefaulttrue
web-worker-ts-config

TypeScript configuration for Web Worker modules.

Value Typestring
Jump to details