My team uses Karma (and thus Jasmine) to test our AngularJS applications.
Sometimes when a single test is failing, it’s a pain to re-run every test while you iterate on a fix.
Turns out there’s a way to only run a single suite of tests, or even a single test.
If you have tests failing in “my feature a”, you can just run those tests by changing the describe call to a ddescribe call.
1234567891011121314151617181920
// Only this suite will runddescribe(“myfeaturea”,function(){it(“hasafoo”,function(){// ...});it(“hasabar”,function(){// ...});});describe(“myfeatureb”,function(){it(“hasafoo”,function(){// ...});it(“hasabar”,function(){// ...});});
If you’ve narrowed down to a single spec, you can re-run that single spec by changing it to iit.
1234567891011121314151617181920
describe(“myfeaturea”,function(){// Only this spec will runiit(“hasafoo”,function(){// ...});it(“hasabar”,function(){// ...});});describe(“myfeatureb”,function(){it(“hasafoo”,function(){// ...});it(“hasabar”,function(){// ...});});
If you want to run multiple specs, you do that by simply changing each to iit.
123456789101112131415161718192021
describe(“myfeaturea”,function(){// This spec will runiit(“hasafoo”,function(){// ...});it(“hasabar”,function(){// ...});});describe(“myfeatureb”,function(){// This spec will runiit(“hasafoo”,function(){// ...});it(“hasabar”,function(){// ...});});
This was a pretty useful discovery for me. Hopefully it is for you as well.
Update: David Ruttka has pointed out that you can also use xdescribe and xit to disable individual suites and tests.
I am now accepting new clients for part-time consulting and software development projects.
Learn more