Last Updated: September 09, 2019
·
5.105K
· tmpduarte

Jasmine - run a selected set of tests

You start to develop a new application and as an awesome programmer you write tests for your code.
Everything is tested, tests are green, life is great.

As soon as your application starts to grow, the number of tests also grows and you stumble upon the problem that every time you (re)write a test or a suite of tests for a new feature you need to run all the tests again.
You fix a small issue or typo you detected and, again, you run all of them.
The problem is that the tests can take some time to run, specially if you have end to end tests they can take a couple of minutes to run.

Jasmine provides us with the possibility to run a specific test or set of tests.
You just need to prepend the it("should do something", function(){...}) with an f (fit("should do something", function() {...})) this makes jasmine runs only the tests (it's) prepended with f (focus).
The same happens with describe's, prepend a describe with f (fdescribe) and jasmine will run all the set of tests (describe's) prepended with f (focus).

One last thing, fit's have more precedence than fdescribe's, this means that jasmine will ignore fdescribe's if one or more fit's are present, this way running only the fit's.

PS.: don't forget to remove all prepended f's before commiting, also, run the tests again to make sure every test pass and that all of them ran.
This is a realy nice feature but it can lead to mistakes, very often developers forget to remove them.

PS2.: A big thanks to @tykayn for the update.

3 Responses
Add your response

I wanted to know that... thanks for sharing... :)

over 1 year ago ·

hi, now the iit() and ddescribe() functions have been replaced to fit() and fdescribe()
:)

over 1 year ago ·

Thanks @tykayn, I have updated the protip accordingly.
In my defense I'm now doing more iOS so I haven't used jasmine for a while :D

over 1 year ago ·