问题描述
describe('#indexOf()'....
it('#doSth()');
#"在摩卡咖啡中是否有特殊含义? describe
和it
实际做什么?抱歉,找不到describe
和it
Does '#' has special meaning in Mocha? What does describe
and it
actually do? sorry not found document for describe
and it
推荐答案
describe
和it
遵循称为BDD
的模式,表示行为驱动开发".它只是定义了一个接口,使您对编写测试的方式有所不同,至少应该如此.嵌套describe
还可以按功能对测试进行分组,并且生成的报告对此具有可读性".
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
是运行的实际测试. #
没有特殊含义.在这种情况下,它只会使输出文本/报告看起来更像API文档.
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.
这篇关于“#"在摩卡咖啡中是否有特殊含义?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!