javascript - Mocha 中的 describe() 是什么

标签 javascript node.js express mocha.js

我正在尝试使用 Mocha,这是我从文档中看到的示例:

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 语句

  describe('#indexOf()', function(){

#indexOf() 中以 # 开头。这个#有什么意义?为什么不能简单的写成indexOf呢?我在哪里可以基本了解 describe 的工作原理?

PS:我查看了 http://visionmedia.github.io/mocha/#interfaces 的文档但无法弄清楚这些是如何出现的以及这些接口(interface)是如何处理的。

谢谢

最佳答案

mocha 的 bdd 语法是在 ruby​​ 的 RSpec 中得到启发的。 ,因此您会找到有关搜索 RSpec 的 mocha 约定的最佳提示,这是一个很好的起点:

http://betterspecs.org/

特别提到了#:

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.

关于javascript - Mocha 中的 describe() 是什么,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21353562/

相关文章:

node.js - 获取 Gists 的 Cors 选项

javascript - 将 Sequelize 与 bcrypt async 一起使用

javascript - Bower - EPERM,取消链接错误

mysql - 有没有办法将值从mysql回调函数传递到express中的外部函数?

node.js - Express 应用程序不允许我检查 req 中的内容

node.js - Nodemon 不会在 docker 中使用 Express 更改时重新加载文件

javascript - 谷歌地图 lng + lat 到隐藏字段不起作用

javascript - 是否可以在 VueJS 中外包生命周期钩子(Hook)

Javascript:更新矩阵数组

javascript - Polymer 2.0 dom-if 渲染模板,即使条件为 false