ngt 1.0.40
See the version list below for details.
dotnet tool install --global ngt --version 1.0.40
dotnet new tool-manifest
dotnet tool install --local ngt --version 1.0.40
#tool dotnet:?package=ngt&version=1.0.40
nuke :add-package ngt --version 1.0.40
ngt - Angular Unit Test Generator
A .NET CLI tool to automatically generate Jest, Vitest, or Jasmine/Karma unit tests for Angular TypeScript files with 80% test coverage target.
Features
- Global .NET Tool - Install once, use anywhere with the
ngtcommand - Runner-Aware - Auto-detects the workspace's test runner (Vitest, Jest, or Jasmine/Karma) and emits the matching mock API (
vi.fn(),jest.fn(), orjasmine.createSpy()) - Smart File Detection - Automatically identifies components, services, guards, interceptors, pipes, directives, and resolvers
- Modern Angular Support - Handles both functional (arrow function) and class-based patterns
- Standalone Components - Detects and properly tests standalone components and directives
- Dependency Detection - Automatically mocks HttpClient, Router, AuthService, and injection tokens
- Overwrite by Default - Regenerates
name.spec.tsin place; pass--overwrite falseto keep existing specs and write numbered files instead (e.g.,.spec.2.ts) - Clean Command -
ngt cleandeletes every generated.spec.tsunder a folder (with--dry-runto preview), skippingnode_modules,dist, and other excluded directories - Workspace Aware - Automatically detects Angular workspaces via
angular.json
Quick Start
Installation
Install the tool globally from NuGet:
dotnet tool install --global ngt
Updating to the latest version
If an older version is already installed, dotnet tool install fails with Tool 'ngt' is already installed. Use update instead to pull the latest version from NuGet:
dotnet tool update --global ngt
Verify which version you have at any time:
ngt --version # version of the installed tool
dotnet tool list --global # all global tools and their versions
Usage
Navigate to your Angular project and generate tests:
cd /path/to/angular-app/src/app
ngt generate
Or specify a path — either a folder (scoped to it and its subfolders) or a single file:
# A folder: generate for it and everything beneath it
ngt generate --path /path/to/angular/app/src/app
# A single file: generate the spec for just that file
ngt generate --path /path/to/angular/app/src/app/user.service.ts
Example Output
Detected Angular workspace at: /home/user/my-angular-app
Generating tests for: /home/user/my-angular-app/src/app
Found 12 TypeScript file(s) to process.
✓ Generated: app.component.spec.ts
✓ Generated: user.service.spec.ts
✓ Generated: auth.guard.spec.ts
✓ Generated: auth.interceptor.spec.ts
✓ Generated: date-format.pipe.spec.ts
- Skipped: user.model (interface/type only)
Test generation complete:
Success: 10
Skipped: 2
Failed: 0
Total: 12
Supported File Types
| Type | File Pattern | Features |
|---|---|---|
| Components | *.component.ts |
TestBed, fixtures, standalone detection |
| Services | *.service.ts |
HTTP mocking, method-level tests |
| Guards | *.guard.ts |
Functional & class-based, auth mocking |
| Interceptors | *.interceptor.ts |
HTTP testing, token injection |
| Pipes | *.pipe.ts |
Transform testing |
| Directives | *.directive.ts |
Host component testing |
| Resolvers | *.resolver.ts |
Route data resolution |
Documentation
- Getting Started - Installation and quick start guide
- User Guide - Complete usage documentation
- Configuration - Configuration options
- Supported Types - Detailed guide for each Angular type
- Examples - Complete source and test examples
- Troubleshooting - Common issues and solutions
- Contributing - How to contribute
Prerequisites
- .NET 9.0 SDK or later
- An Angular application with TypeScript files
Command Reference
Generate Command
ngt generate [options]
| Option | Alias | Description |
|---|---|---|
--path |
-p |
A TypeScript file or a folder to generate tests for (optional). A folder is scoped to it and its subfolders; a file generates a spec for that file only. |
--overwrite |
-o |
Overwrite an existing .spec.ts in place (default: true). Use --overwrite false to keep existing specs and write .spec.2.ts, .spec.3.ts, … |
--help |
-h |
Show help |
Clean Command
Delete the generated test files. clean removes every *.spec.ts in a folder and its
subfolders, skipping excluded directories (node_modules, dist, .angular, …) so a
dependency's specs are never touched. Only files ending in .spec.ts are removed — your
sources, .test.ts files, and discriminated .spec.2.ts files are left alone.
ngt clean [options]
# Preview what would be deleted, without deleting anything
ngt clean --path ./src/app --dry-run
# Delete all .spec.ts files under the current directory (must be inside an Angular workspace)
ngt clean
| Option | Alias | Description |
|---|---|---|
--path |
-p |
The folder to clean (optional). All .spec.ts files in this folder and its subfolders are deleted. When omitted, defaults to the current directory — but only when run inside an Angular workspace (angular.json found by walking up), the same guard generate applies. |
--dry-run |
-n |
List the .spec.ts files that would be deleted without deleting anything. |
--help |
-h |
Show help |
Global Options
ngt --version # Show version
ngt --help # Show help
Configuration
Create appsettings.json in your project to customize behavior:
{
"AngularTestGenerator": {
"TargetCoveragePercentage": 80,
"TestFileExtension": ".spec.ts",
"ExcludedDirectories": ["node_modules", "dist", ".angular", "coverage"]
}
}
See Configuration Guide for all options.
How It Works
- Discovery - Scans the directory for TypeScript files, excluding
node_modules,dist, and existing test files - Analysis - Determines file type, extracts class names, detects dependencies, and identifies patterns (functional vs class-based)
- Generation - Creates appropriate test files with TestBed configuration, mocks, and basic test cases
- Naming - Regenerates
name.spec.tsin place by default; with--overwrite false, an existing spec is preserved and a discriminating number is added instead (e.g.,.spec.2.ts)
Project Structure
src/AngularUnitTests.Cli/
├── Commands/ # CLI command definitions
├── Services/ # Core services (discovery, generation)
├── Models/ # Data models
├── Configuration/ # Options and settings
└── Program.cs # Entry point
Development
Build from Source
git clone https://github.com/QuinntyneBrown/AngularUnitTests.git
cd AngularUnitTests
dotnet build
Run Tests
dotnet test
Install Local Build
dotnet pack src/AngularUnitTests.Cli/AngularUnitTests.Cli.csproj -o ./nupkg
dotnet tool install --global --add-source ./nupkg ngt
Continuous Integration & Publishing
| Workflow | Trigger | What it does |
|---|---|---|
| CI | push / PR to main |
Restores, builds, and tests the solution on Linux, Windows, and macOS |
| Publish to NuGet | push to main / manual |
Builds, tests, packs, and pushes ngt to NuGet with --skip-duplicate |
Publishing pushes the package only when the <Version> in
AngularUnitTests.Cli.csproj
is new, so bump it to cut a release. The workflow requires a NUGET_API_KEY
repository secret.
Contributing
Contributions are welcome! Please read CONTRIBUTING.md and follow our Code of Conduct.
License
MIT — see LICENSE.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net9.0 is compatible. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
This package has no dependencies.