The 'describe' keyword in javascript

JavascriptJqueryCordovaspine.js

Javascript Problem Overview


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

Javascript Solutions


Solution 1 - Javascript

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.

Solution 2 - Javascript

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

Solution 3 - Javascript

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.

Solution 4 - Javascript

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

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionAatish MolasiView Question on Stackoverflow
Solution 1 - JavascriptmmigdolView Answer on Stackoverflow
Solution 2 - JavascriptyngcccView Answer on Stackoverflow
Solution 3 - Javascriptg.yView Answer on Stackoverflow
Solution 4 - JavascriptShaik Mohammad AbdullahView Answer on Stackoverflow