91

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

0

6 Answers 6

115

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.

3
  • 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, 2012 at 5:58
  • Found this via google. You should update the link. Seems to be jasmine.github.io these days.
    – Xaekai
    Feb 13, 2015 at 17:50
  • 2
    discribe is also provide by another Javascript test framework "MochaJs".
    – btpka3
    Jul 20, 2016 at 10:11
26

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

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.

1

jest also has describe function.

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

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.