Run a single unit test with Mocha/Chai

Sure, you can add file globbing patterns to a CLI arg to run a single JavaScript test, or group of tests, but it’s not super convenient and often requires a trip to your README to remember how to do it. Here’s a quicker way.


Instead of hunting for the exact CLI params and globs, just add .only  to your it()  as shown below:

Take note:  If you use .only()  on more than one it() , it will only run the last test case.


And it works with a single group of tests, as well! Just add .only to your describe() as shown below:

Wrap up

There you have it! Single test groups and/or cases without screwing with CLI parameters.

Be sure to remove all instances of .only from your describe()  and it()  statements before committing to a repo, or you risk having your CI/CD pipeline run only a subset of your tests!

Author: Grant Norwood

Designer of things you click. Vegetable rights activist. Volunteer with tiny humans. Austin-ish, Texas.

People describe me as a rad web developer, product manager, solutions architect, public speaker, volunteer, and non-profit board member.

Did you know you can leave a comment?

%d bloggers like this: