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
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With