我阅读了所有相关的mocha“describe”未定义
帖子,但似乎都不适合我的情况。
我使用meteor并通过npm
安装了"mocha": "^3.5.0"
包
我在meteor根目录中创建了一个/test
文件夹。
和示例测试 mochatest.js
var assert = require("assert"); // node.js core module
describe('Array', function(){
describe('#indexOf()', function(){
it('should return -1 when the value is not present', function(){
assert.equal(-1, [1,2,3].indexOf(4)); // 4 is not present in this array so indexOf returns -1
})
})
});
当我运行 mocha 时,测试通过。
但是当我启动普通服务器时,我得到:ReferenceError:describe is not Define
.meteor/packages/meteor-tool/.1.3.5_1.1wj76e8++os.linux.x86_64+web.browser+web.cordova/mt-os.linux.x86_64/dev_bundle/server-lib/node_modules/fibres/future.js:280
抛出(前);
^
ReferenceError:描述未定义
在meteorInstall.test.mochatest.js (test/mochatest.js:3:1)
在 fileEvaluate (packages/modules-runtime/.npm/package/node_modules/install/install.js:153:1)
在需要时(packages/modules-runtime/.npm/package/node_modules/install/install.js:82:1)
在项目-i18n.js:6:1
在 .meteor/local/build/programs/server/boot.js:297:10
at Array.forEach( native )
在函数.__.each._.forEach(.meteor/packages/meteor-tool/.1.3.5_1.1wj76e8++os.linux.x86_64+web.browser+web.cordova/mt-os.linux.x86_64/dev_bundle/server-lib/node_modules/underscore/underscore.js:79:11)
在 .meteor/local/build/programs/server/boot.js:133:5
我有一种感觉,meteor 想要在启动时运行测试,但找不到 mocha 的东西。
那该怎么办?
最佳答案
您需要将/test
文件夹重命名为/tests
。
来自官方Meteor Testing Guide :
The Meteor build tool and the meteor test command ignore any files located in any
tests/
directory. This allows you to put tests in this directory that you can run using a test runner outside of Meteor’s built-in test tools and still not have those files loaded in your application.
您还可以考虑使用以下扩展名重命名测试文件:
*.test[s].*
或 *.spec[s].*
-- 因此您的文件可以命名为 mocha.test.js
。
此类文件也会被 Meteor 构建工具忽略。
关于javascript - Mocha "describe"未定义,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45543254/