How to run a single test file with Karma/Jasmine?

11,236

Although it's not ideal, you can replace describe (and it) with fdescribe (and fit) so only those tests will be executed

On the other hand, xdescribe / xit excludes the tests from your suite

If you use Gulp, you can combine gulp-karma & yargs to pass in a pattern as argument.

source: https://stackoverflow.com/a/27696472/1782659

Share:
11,236

Related videos on Youtube

Anton Belev
Author by

Anton Belev

Updated on July 01, 2022

Comments

  • Anton Belev
    Anton Belev almost 2 years

    I'm using Karma and Jasmine for testing my Angular JS code. I managed to run all the tests in my project using Karma, but if I try to run just a single file I'm getting the following error: ReferenceError: describe is not defined. Is it possible to run just a single test file and if yes then how?

    P.S. I'm using Intellij IDEA.

  • Anton Belev
    Anton Belev over 8 years
    That's not an option : ) we have 3500+ tests. The idea is if you've just included a new test file and you want to run just this one. So far the only way is to comment out all the other test files from the karma.conf.js file.
  • Pieter Willaert
    Pieter Willaert over 8 years
    the -f- option (focus) does just that (don't forget to remove it again before you commit)
  • Jason
    Jason almost 8 years
    Blech. it.only and describe.only are so much more intuitive. This worked, however. Thank you.
  • Lee Jensen
    Lee Jensen over 6 years
    Here is a good post (JSGuy) about this functionality.
  • Emir Herrera
    Emir Herrera about 4 years
    So far a remember there is a lint setting or something like that to avoid commit focussed test commits.