mocha:无法读取未定义的 属性 'be'

mocha: Cannot read property 'be' of undefined

我正在为我的项目编写单元测试。但是我总是遇到这个问题

无法读取未定义的 属性 'be'。

我有一个名为 model-xxx 的测试套件,我想尝试这个模型中的每个方法。所以每个方法我都在 model-xxx 中写了一个子测试套件。像这样:

enter image description here

而且每个方法都与猫鼬有关,所以我希望这些子套件是异步的。所以我在 beforeafterit

中写的每个方法

但这些套件中的 none 通过了。像这样的错误:

enter image description here

像这样:

Cannot read property 'not' of undefined.

为什么会出现这种情况?这是否意味着我的 should.js 有问题?但没有意义

希望得到解决方案。

Chai 的 should 是一个 函数,需要先调用它才能使用 should 样式的断言:

var should = require('chai').should();

参见the documentation