Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does '#' has special meaning in Mocha?

describe('#indexOf()'....
it('#doSth()');

Does '#' has special meaning in Mocha? What does describe and it actually do? sorry not found document for describe and it

like image 262
nfpyfzyf Avatar asked Apr 25 '13 05:04

nfpyfzyf


1 Answers

describe and it follows a pattern called BDD, which means "Behaviour Driven Development". It just defines an interface that makes you think a little different about how you write your tests, at least it should. Nesting of describe also makes it possible to group your tests functionally, and the resulting report has a "readable" feeling to it.

Quoting the example from the Mocha docs:

describe('Array', function(){
    describe('#indexOf()', function(){
        it('should return -1 when the value is not present', function(){
            assert.equal(-1, [1,2,3].indexOf(5));
            assert.equal(-1, [1,2,3].indexOf(0));
        })
    })
})

It reads:

Array#indexOf() should return -1 when the value is not present

The first two describes just sets up the (descriptional/grouping) scope, and the it is the actual test that is run. # has no special meaning. In this case, it just makes the output text/report look a little more API-doc like.

like image 199
NilsH Avatar answered Oct 18 '22 00:10

NilsH