摩卡中的describe()是什么 [英] What is describe() in Mocha
问题描述
我正在尝试弄清Mocha,这是我从文档中看到的示例:
I am trying to get my hands dirty with Mocha and here is the example I saw from documentation:
var assert = require("assert")
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));
})
})
})
大多数示例都显示了第二个describe语句
Most of the examples show the second describe statement
describe('#indexOf()', function(){
从#indexOf()
中的#
开始. #
的意义是什么?为什么不能将其简单地写为indexOf
?在哪里可以对描述的工作原理有基本的了解?
starting with #
in #indexOf()
. What is the significance of this #
? Why can this not be written simply as indexOf
? Where can I get a fundamental understanding of how the describe works?
PS:我看了 http://visionmedia.github.io/mocha/#上的文档界面,但无法弄清楚它们是如何出现的以及如何处理这些界面.
PS: I looked at the documentation at http://visionmedia.github.io/mocha/#interfaces but can't figure out how these came into picture and how are these interfaces processed.
Thx
推荐答案
mocha的bdd语法是ruby的 RSpec 的启发.会找到Mocha约定搜索RSpec的最佳技巧,这是一个不错的起点:
the bdd syntax of mocha is a inspired in ruby's RSpec, therefore you'd find the best tips for mocha's conventions searching for RSpec, here's a good place to start:
特别是其中提到了#
:
例如,使用的Ruby文档约定. (或::)表示类方法的名称,#表示实例方法的名称.
For instance, use the Ruby documentation convention of . (or ::) when referring to a class method's name and # when referring to an instance method's name.
这篇关于摩卡中的describe()是什么的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!