javascript - Mocha "describe"未定义

标签 javascript node.js meteor mocha.js

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

相关文章:

javascript - meteor - 在选择更改时更新 var

javascript - 防止代码在 forEach 之后执行

javascript - getElementsByTagName 排除元素(过滤器)

javascript - 在单页应用程序中选择菜单时调用 Controller - angularJs

jquery - 在 Node.js 中使用数据表

meteor - 如何在 meteor 中最后加载CSS包?

javascript - 如何在 jest/enzyme 中测试包含 useIsFocused() 导航钩子(Hook)的 react-native 文件?

javascript - Nodejs 中长时间运行的请求

node.js - 当涉及到 Node.js 生命周期时,我有哪些选择?

javascript - 从meteor中的JSONP中提取数据