describe and it follows a template called BDD , which means "Behavior Driven Development". It just defines an interface that makes you think a little differently about how you write your tests, at least that's what you need. The describe attachment also allows you to group your tests functionally, and the final report has a βreadableβ feel for it.
Quoting an example from 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 no value
The first two describe simply setting the scope (description / grouping), and it is the actual test that is being performed. # doesn't really matter. In this case, it just makes the text / report output more like an API doc.
NilsH Apr 25 '13 at 5:28 2013-04-25 05:28
source share