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

2020-08-13 23:25发布

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.

2条回答
放我归山
2楼-- · 2020-08-13 23:51

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

查看更多
Evening l夕情丶
3楼-- · 2020-08-14 00:01

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
查看更多
登录 后发表回答