How do I run only certain tests in karma?

deitch picture deitch · Oct 28, 2014 · Viewed 10.6k times · Source

I have karma config set up correctly, config file, running in the background, just great. As soon as I change and save a file, it reruns the tests.... all 750 of the unit tests. I want to be able to run just a few. Short of manually hacking the config file or commenting out hundreds of tests across many files, is there any easy way to do it?

E.g. when running command line server tests using say mocha, I just use regexp: mocha -g 'only tests that I want'. Makes it much easier to debug and quickly check.

Answer

deitch picture deitch · Oct 29, 2014

So now I feel foolish. mocha supports a very narrow version of regexp matching.

This runs all tests

describe('all tests',function(){
   describe('first tests',function(){
   });
   describe('second tests',function(){
   });
});

This runs just 'first tests'

describe('all tests',function(){
   describe.only('first tests',function(){
   });
   describe('second tests',function(){
   });
});

You can also do it.only()

I should have noticed that. Sigh.