how do I run a single test from the command line using jasmine 2.0
Asked Answered
G

4

7

As the title says, I would like to run a single test, not the whole spec. The naive way I tried was using a case like this:

describe("MyCase",function() {
    it("has a test",function() {
        expect(something).toBe(something);
    }

    it("has another test",function() {
        expect(something_else).toBe(something_else);
    }
}

This is saved in a file called MyCase.spec.js (if this matters). I would have thought that it would be possible to run just the first case using the following from the command line:

jasmine-node --match="MyCase has a test"

But this is apperantly not the way to do it. So how is it done?

Thanks!

Greerson answered 28/9, 2014 at 5:35 Comment(0)
V
6

it may be pretty old channel but it would help someone who is looking for running specific testcase with jasmine 2.0. Use "fdescribe" to run a specific suite and use "fit" to run a specific spec.This skips all other tests except marked.

keep an eye and not to commit fdescribe and fit to repo. Here f describe the "focus".

For lower versions we can use ddescribe, iit as described in upper answers.

Vaientina answered 25/10, 2016 at 7:20 Comment(1)
Took me a while to find this, thanks. Annoying with .only() and 'iit' not working.Satanic
D
4

Change it with iit and run your test as usual. Thus only this test will be run and all others will be ignored.

E.g.

iit('should run only this test', function () {
    //expect(x).toBe(y);
});

The same works for the describe block, just rename it to ddescribe

Also you can ignore a single it test by renaming it to xit

And xdescribe works too

Defunct answered 17/11, 2014 at 15:43 Comment(1)
This is such a terrible solution. Changing tests every time i want to isolate a test, is just as tedious/slow as running all my tests. This is a bad practice in my opinionBeestings
L
4

Not sure if it is applicable for jasmine-node, but using ts-node and Jasmine's node modules path, I can use the filter flag to match the spec's string. For me it looks like:

ts-node node_modules/jasmine/bin/jasmine --filter="employees*"

This would match all the 'it' blocks within a 'describe' block that begin with 'employees'.

Lovett answered 12/8, 2020 at 15:3 Comment(0)
P
0

It might not be what you need exactly, but I would like to propose using karma / karma-jasmine. Within Karma, Jasmine is "patched" and provides additional ddescribe and iit methods. If you rename one of your suites to ddescribe or one of your specs to iit (takes precedence over ddescribe), only this suite or spec will be executed. Concerning your question, you could rename your first spec to iit and then only this spec would be executed. Of course, this is only useful while developing the spec.

A downside on this is, that one can easily end up having only a fraction of one's test suites being tested for a long time. So don't forget to rename it back to the usual version (no double d's, no double i's).

Putto answered 29/9, 2014 at 19:45 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.