Since at least 2019:

npm test -- bar.spec.js

In 2015:

In order to run a specific test, you'll need to use the jest command. npm test will not work. To access jest directly on the command line, install it via npm i -g jest-cli or yarn global add jest-cli.

Then simply run your specific test with jest bar.spec.js.

Note: You don't have to enter the full path to your test file. The argument is interpreted as a regular expression. Any part of the full path that uniquely identifies a file suffices.

Answer from ncuillery on Stack Overflow
Discussions

ng test specific file
Is it possible to specify a path to a specific file when running ng test? Or only run tests in specific files somehow? Can't seem to find any issues or documentation about it anywhere. Thanks! ... More on github.com
🌐 github.com
21
November 3, 2016
Cannot run a single test file
I used to run single test files (on Windows, simple terminal) with the following command: ... I believe the testPathPattern is an option of Jest, but it worked as is. After upgrading the Angular 14.1.0 (and Jest 28, jest-preset-angular 12.2.0, etc.), it no longer work. $ ng test --testPath... More on github.com
🌐 github.com
2
July 28, 2022
Support single-file running of Unit testing
We'd like the ability to run the tests against single unit tests files instead of the whole project so we can narrow down incompatibilities with the testing infrastructure we're coming from and to try and squash the ridiculous memory usage we're experiencing. ... Allow adding a unit test file to the ng test script to just run that specific test. We've considered going back to our Jest ... More on github.com
🌐 github.com
2
July 11, 2025
Run A Single Unit Test
OS? Windows 8, Mac OSX El Capitan Versions. angular-cli: 1.0.0-beta.19-3 node: 6.3.0 os: win32 x64 Mention any other details that might be useful. This is a feature request. The ability to run a si... More on github.com
🌐 github.com
40
December 16, 2016
🌐
Stack Overflow
stackoverflow.com › questions › 61715565 › angular-9-how-to-run-a-single-spec-file-when-using-jest
testing - Angular 9 how to run a single spec file when using Jest? - Stack Overflow
May 10, 2020 - First of all, try installing same version of Jest globally which is present in your package.json. Using this command - ... Replace xx.yy.zz with the version mentioned in package.json. Then run this command to test single file.
🌐
GitHub
github.com › angular › angular-cli › issues › 3005
ng test specific file · Issue #3005 · angular/angular-cli
November 3, 2016 - Is it possible to specify a path to a specific file when running ng test? Or only run tests in specific files somehow? Can't seem to find any issues or documentation about it anywhere. Thanks! OS Mac OSX (El Capitan) Versions angular-cli...
Author   kirjai
🌐
Just JeB
justjeb.com › post › angular-cli-ng-test-with-jest
Angular CLI: “ng test” with Jest in 3 minutes
June 27, 2022 - Replace jasmine in types array with jest You want your tests to be type-checked against Jest typings and not Jasmine · Remove test.ts from files array This file was responsible for Karma setup, you don’t need it here anymore
🌐
GitHub
github.com › angular › angular-cli › issues › 23651
Cannot run a single test file · Issue #23651 · angular/angular-cli
July 28, 2022 - $ ng test --include=./**/memo-mention*.ts Error: Unknown argument: include · Note that include is mentioned in https://angular.io/cli/test, so it should work… · Note also I can use Jest Runner to run a single test; but it requires to have ...
Author   PhiLhoSoft
🌐
Inspirnathan
inspirnathan.com › posts › 148-how-to-test-single-file-with-jest
How to Test a Single File with Jest - inspirnathan.com
October 14, 2022 - By default, Jest will try to run files that end in .test.js or .spec.js, but we can also pass the name of a file or directory to the Jest CLI to tell it to run only one file instead.
🌐
Angular
v17.angular.io › cli › test
ng test
Angular is a platform for building mobile and desktop web applications. Join the community of millions of developers who build compelling user interfaces with Angular.
Find elsewhere
🌐
Sauce Labs
saucelabs.com › home › blog › three ways to run a single test in jest
Three Ways To Run A Single Test In Jest
September 15, 2023 - In this post, you'll learn how to how to run a single test using Jest, a popular JavaScript testing framework. Jest executes all tests in parallel by putting each test file in a different process by default.
🌐
Medium
medium.com › self-learning › run-single-test-file-in-angular-workspace-typescript-only-e1212b52c7db
Run Single Test File in Angular Workspace by Jasmine(TypeScript Only) | by Ben Cheng | Medium
September 17, 2019 - import { AppComponent } from './app.component';describe('AppComponent', () => { const component = new AppComponent(); it('test', () => { expect(component.title).toBe('angular-jasmine-workspace'); }); });
🌐
GitHub
github.com › angular › angular-cli › issues › 30707
Support single-file running of Unit testing · Issue #30707 · angular/angular-cli
July 11, 2025 - ... Allow adding a unit test file to the ng test script to just run that specific test. We've considered going back to our Jest runner, as that allows us to specify single test files to run the testing apparatus on.
Author   quinnjr
🌐
GitHub
github.com › angular › angular-cli › issues › 3603
Run A Single Unit Test · Issue #3603 · angular/angular-cli
December 16, 2016 - This is a feature request. The ability to run a single .spec.ts file would be excellent, when you guys get the chance. I recently switched from using Angular1 in Visual Studio where one could use the Test Explorer or the Chutzpah extension to run a test on a single component.
Author   jongunter
🌐
DZone
dzone.com › testing, deployment, and maintenance › testing, tools, and frameworks › running a karma test case for a single spec file / single module
Running a Karma Test Case for a Single Spec File / Single module
May 23, 2018 - This quick tutorial shows how to run unit test cases on a single spec file when using Karma and Jasmine for your Angular unit tests, to save you time.
🌐
Reddit
reddit.com › r/angular2 › [nx angular] run specific test locally
r/Angular2 on Reddit: [Nx Angular] Run specific test locally
February 6, 2025 -

I tried many commands that I could find regarding this topic but nothing worked out. What I’m trying to do is execute a single spec.ts file.

• ⁠Angular & Nx Version 17

How do I do that?

Edit: resolved

=> nx test <library> —include=libs/path-to-spec.ts

library = project.json: value of name

🌐
Medium
medium.com › angular-in-depth › angular-cli-ng-test-with-jest-in-3-minutes-v2-1060ddd7908d
Angular CLI: “ng test” with Jest in 3 minutes (v2) | by Jenia Barabanov | Angular In Depth | Medium
June 27, 2022 - You can specify Jest CLI options ... when it is a one-timer). For example to run a single test: ng test --test-name-pattern="My test suite My test case"...
🌐
Geshan
geshan.com.np › blog › 2022 › 07 › jest-run-single-test
Two useful ways to easily run a single test using Jest
July 30, 2022 - After that, the --testPathPattern Jest CLI parameter was discussed to target tests written on a specific file. Subsequently, the --coverage and --collectCoverageFrom Jest CLI parameters were used to not only run a single test with just but also report code coverage from a single file while running specific tests.
🌐
CodeBurst
codeburst.io › angular-6-ng-test-with-jest-in-3-minutes-b1fe5ed3417c
Angular CLI: “ng test” with Jest in 3 minutes | by Jenia Barabanov | codeburst
May 21, 2022 - You can specify Jest CLI options ... (useful when it is a one-timer). For example to run a single test: ng test --testNamePattern="My test suite My test case"...
🌐
CopyProgramming
copyprogramming.com › howto › angular-ng-test-only-one-file-code-example
Angular: Code Example for Testing a Single File in Angular using ng test
July 22, 2023 - Before proceeding, ensure that ... ... Npm run test specific file Code Example, xxxxxxxxxx. 1. n order to run a specific test, you'll need to use the jest command....