跳到主要内容
CNode

我安装了mocha模块,为何出现`ReferenceError: describe is not defined`

问答
Nnapster99发布于 12 年前最后回复 8 年前
10354330
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));
        })
    })
});

我安装了mocha模块,为何出现ReferenceError: describe is not defined 怎么回事??

查看回复

回复 (10)

Y
YueweiGuo#108 年前

呃,使用Visual Studio Code,6楼正解,使用 mocha test.js 执行,不会报错 QQ图片20180702161331.png

A
alsotang#911 年前
引用 qinghechaoge我是windows系统 npm install g mocha 成功了 node app.test 提示 describe is not defined mocha app.test 提示 '...

@qinghechaoge 想办法找到 mocha 的可执行文件,然后用它来运行你的测试文件。

Q
qinghechaoge#811 年前

我是windows系统 npm install -g mocha 成功了 node app.test 提示 describe is not defined mocha app.test 提示 'mocha' 不是内部或外部命令,也不是可运行的程序或批处理文件。

S
sunyonggang#611 年前

mark一下,我使用的是webstorm,遇到了同样的问题,解决方法是使用mocha指定去执行而不是使用node直接执行

I
i5ting#512 年前

确定npm install --save mocha 成功了?

I
i5ting#412 年前
引用 slightboy全局安装 mocha test.js

@slightboy 不用全局的,在.node_modules/.bin/mocha里

O
OneDaySunshine#212 年前

请问你你这个问题搞定了没? 我现在也遇见同样的问题了

S
slightboy#112 年前

全局安装 mocha test.js

参与回复

登录后即可参与回复。登录