Mastering Web Application

(Rick Simeone) #1
Chapter 2

Executing a subset of tests

The Jasmine version shipped with Karma runner has very useful extensions to
quickly isolate a set of tests to run:



  • Prefixing a test or a suite with the x character (xit, xdescribe) will disable
    this tests/suite during the next run.

  • Prefix a test suite with the d character (ddescribe) will only run this suite,
    ignoring others.

  • Prefixing a test with the i character (iit) will only run this test, ignoring
    other tests and suites.


Those little prefixes are extremely useful in practice and can be used as shown below:


describe('tips & tricks', function () {

xdescribe('none of the tests here will execute', function () {

it('won't execute - spec level', function () {
});

xit('won't execute - test level', function () {
});
});

describe('suite with one test selected', function () {

iit('will execute only this test', function () {
});

it('will be executed only after removing iit', function () {
});
});

});

Debugging

Narrowing down a failing test is half of the success. Still we need to understand
what is going on, and this often involves a debugging session. But how to debug
tests executed by Karma runner? It turns out that it is pretty easy; it is enough to add
the debugger statement in our test or production code.

Free download pdf