11

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.

Luis Limas
  • 2,118
  • 18
  • 31
Anton Belev
  • 7,909
  • 18
  • 59
  • 103

2 Answers2

9

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

Community
  • 1
  • 1
Pieter Willaert
  • 836
  • 12
  • 33
  • 3
    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. – Anton Belev Nov 10 '15 at 09:50
  • 2
    the -f- option (focus) does just that (don't forget to remove it again before you commit) – Pieter Willaert Nov 10 '15 at 10:01
  • 1
    Blech. it.only and describe.only are so much more intuitive. This worked, however. Thank you. – Jason Jul 24 '16 at 20:47
  • Here is a [good post (JSGuy)](https://thejsguy.com/2016/01/03/controlling-which-tests-run-in-jasmine.html) about this functionality. – Lee Jensen Jan 12 '18 at 15:45
  • So far a remember there is a lint setting or something like that to avoid commit focussed test commits. – Emir Herrera Jun 14 '20 at 22:02
0

If you are like me and you've inherited a suite of tests that are controlled by a task runner (e.g. gulp) and you are getting failures but are unsure which file is actually failing you can sanity check an individual file by running jasmine directly against it:

1.) Make sure you have jasmine installed (it may not be if wrapped inside your task runner configuration)

npm install jasmine

2.) Run jasmine against file:

./node_modules/.bin/jasmine /path/to/my/spec/file.js

or

./node_modules/jasmine/bin/jasmine.js /path/to/my/spec/file.js
GreensterRox
  • 4,680
  • 2
  • 19
  • 29