89

So I am a newbie in javascript and i had been going through some one else's code and I found this..

describe('deviceready', function() {
    it('should report that it fired', function() {
        spyOn(app, 'report');
        app.deviceready();
        expect(app.report).toHaveBeenCalledWith('deviceready');
    });
});

What I don't understand is: What exactly does the describe keyword do?

info:
- Its a phonegap application
- We are using the spine.js and jQuery libraries

Kemal Fadillah
  • 9,760
  • 3
  • 45
  • 63
Aatish Molasi
  • 2,138
  • 3
  • 20
  • 43

6 Answers6

114

Describe is a function in the Jasmine testing framework. It simply describes the suite of test cases enumerated by the "it" functions.

Also used in the mochajs framework.

Oliver Watkins
  • 12,575
  • 33
  • 119
  • 225
mmigdol
  • 2,023
  • 1
  • 18
  • 20
  • 13
    It is doing this by setting up a lot of functions that give the whole test case the appearance of being a somewhat natural language sentence. This is called DSL, but it can be quite confusing for those unfamiliar with the library. – Thilo Aug 31 '12 at 05:58
  • Found this via google. You should update the link. Seems to be http://jasmine.github.io/ these days. – Xaekai Feb 13 '15 at 17:50
  • 2
    `discribe` is also provide by another Javascript test framework "[MochaJs](http://mochajs.org)". – btpka3 Jul 20 '16 at 10:11
25

Describe is not part of Javascript, it is a function defined in the library you used (namely Jasmine)

Ankit Jaiswal
  • 22,859
  • 5
  • 41
  • 64
yngccc
  • 5,594
  • 2
  • 23
  • 33
9

According to the Jasmine Documentation

The describe function is for grouping related specs, typically each test file has one at the top level. The string parameter is for naming the collection of specs, and will be concatenated with specs to make a spec's full name.

KyleMit
  • 30,350
  • 66
  • 462
  • 664
g.y
  • 111
  • 1
  • 6
1

jest also has describe function.

https://jestjs.io/docs/api#describename-fn

pakira79
  • 111
  • 2
  • 5
0

The "describe" block is used to group tests together in jest. Have a look at the following link. Go to the scoping section, You shall understand why and how it is been used.

https://jestjs.io/docs/setup-teardown

0

Describe() is a function in the Jest testing framework.

According to the Jest Documentation

  • describe(name, fn) creates a block that groups together several related tests.
  • Also note, it isn't required - you can write the test blocks directly at the top level. But it can be handy if you prefer your tests to be organized into groups.
  • You can also nest describe blocks if you have a hierarchy of tests.
Yogesh Yadav
  • 190
  • 1
  • 2
  • 11