gpt4 book ai didi

javascript - Mocha "describe"未定义

转载 作者:太空宇宙 更新时间:2023-11-04 02:02:19 24 4
gpt4 key购买 nike

我阅读了所有相关的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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com