问题
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
回答1:
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.
回答2:
The '#' has no special meaning. It is a common standard to prefix # to a method for a certain class. e.g. Array#indexOf()
.
I had exactly the same questions on describe()
and it()
, which the documentation didn't explain much.
Hence I wrote a blog post on a guide to mocha. In short:
describe()
is merely for grouping, which you can nest as deep. Also known as a test suite.it()
is a test case
来源:https://stackoverflow.com/questions/16206894/does-has-special-meaning-in-mocha